Showing posts with label http://schemas.google.com/blogger/2008/kind#post. Show all posts
Showing posts with label http://schemas.google.com/blogger/2008/kind#post. Show all posts

26 August 2011

GridView data filter with StoredProcedure

SqlCommand cmd=new SqlCommand();

SqlConnection con = new SqlConnection("..your connection string....");
SqlDataAdapter da=new SqlDataAdapter();
DataSet ds=new DataSet();
cmd.Parameters.Clear();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_getall";
cmd.Connection = con;
cmd.Parameters.Add("@p", SqlDbType.VarChar, 20).Value = txtSearch.Text;
da = new SqlDataAdapter(cmd);
da.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "eName like '" + mr+"'";
gvsearch.DataSource = dv;
gvsearch.DataBind();

create  proc sp_getall
as
begin
select
* from tblemp
end

24 August 2011

checkbox check/uncheck all in gridview


static int kount=0;
protected void chkHead_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chhead = (CheckBox)gv.HeaderRow.FindControl("chkHead");
        foreach (GridViewRow gr in gv.Rows)
        {
            CheckBox ch = (CheckBox)gr.Cells[1].FindControl("chkItem");
            if (chhead.Checked)
                ch.Checked = true;
            else
                ch.Checked = false;
        }
    }



protected void chkItem_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chhead = (CheckBox)gv.HeaderRow.FindControl("chkhead");
        if (gv.Rows.Count == 1)
        {
            CheckBox sinch = (CheckBox)gv.Rows[0].FindControl("chkItem");
            if (sinch.Checked)
                chhead.Checked = true;
            else
                chhead.Checked = false;
        }
        else
        {
            foreach (GridViewRow gr in gv.Rows)
            {
                CheckBox ch = (CheckBox)gr.FindControl("chkItem");
                if (ch.Checked)
                    kount++;
            }
            if (kount == gv.Rows.Count)
                chhead.Checked = true;
            else
            {
                kount = 0;
                chhead.Checked = false;
            }
        }
    }


22 August 2011

how to know the current system name and ip address in asp.net

Response.Write(Request.ServerVariables["REMOTE_ADDR"].ToString()+"
"
);
Response.Write(
HttpContext.Current.Server.MachineName);

grid view sorting and paging in asp.net using C#.net code

protected void gv_Sorting(object sender, GridViewSortEventArgse)
{
DataSet ds = newDataSet();

ds = bal.getdata();

ds.Tables[0].DefaultView.Sort = e.SortExpression +
" " + GetSortDirection(e.SortExpression);
gv.DataSource = ds.Tables[0].DefaultView;

gv.DataBind();

}
privatestring GetSortDirection(string column)
{
string sortDirection = "ASC";
ViewState["SortExpression"] = column;
ViewState["SortDirection"] = sortDirection;string sortExpression = ViewState["SortExpression"] asstring;if (sortExpression != null)
{
string lastDirection = ViewState["SortDirection"] asstring;if ((lastDirection != null) && (lastDirection == "ASC"))
{

sortDirection ="DESC";
}

}
return sortDirection;
}
protectedvoid gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gv.PageIndex = e.NewPageIndex;
getdata();
}

18 July 2011

image field in gridview

source:


 <asp:GridView ID="GridView1" runat="server" DataKeyNames="eid"
onrowcommand="GridView1_RowCommand" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None">

<asp:ImageButton ID="ImageButton1" ImageUrl=''  runat="server"
Height="48px" Width="39px" />


C# code:

SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=sa123;database=empdb");
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gv();
}
}
void gv()
{
da = new SqlDataAdapter("select * from path ", cn);
ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}

findcontrol of datalist control in asp.net



Source:


        <asp:DataList ID="DataList1" runat="server"
onitemcommand="DataList1_ItemCommand">


C# code:


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
da = new SqlDataAdapter("select * from details", con);
ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
TextBox t1 = (TextBox)e.Item.FindControl("TextBox1");
TextBox t2 = (TextBox)e.Item.FindControl("TextBox2");
TextBox t3 = (TextBox)e.Item.FindControl("TextBox3");
TextBox t4 = (TextBox)e.Item.FindControl("TextBox4");

da = new SqlDataAdapter("insert into details values('" + t1.SelectedValue.ToString() + "','" + t2.Text + "','" + t3.Text + "','" + t4.Text + "')", con);
ds = new DataSet();
da.Fill(ds);
this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "alert('Inserted Successfully')", true);
}
}