now first past it on Page_load
public void bind()
{
string qry = "select Id,Category from Admin_Category_Software";
SqlCommand cmd = new SqlCommand(qry, sconn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Columns[1].Visible = false;
}
next bye Item Template
<asp:GridView ID="GridView1" runat="server" Width="684px" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" AllowPaging="True"
AutoGenerateColumns="False" Font-Bold="True" onrowcommand="GridView1_RowCommand"
onrowdatabound="GridView1_RowDataBound"
onrowdeleting="GridView1_RowDeleting"
onselectedindexchanged="GridView1_SelectedIndexChanged" >
<alternatingrowstyle cssclass="alt"></alternatingrowstyle>
<columns>
<asp:templatefield headertext="Operation">
<itemtemplate>
<asp:linkbutton id="LinkButton2" runat="server" causesvalidation="False">
CommandArgument='<%# Eval("Id") %>' CommandName="delete" ForeColor="#009900"
Text="Delete "></asp:linkbutton>
<asp:linkbutton id="LinkButton1" runat="server" causesvalidation="False">
CommandArgument='<%# Eval("Id") %>' CommandName="select" ForeColor="#009900"
Text="Update"></asp:linkbutton>
</itemtemplate>
<itemstyle width="100px" />
</asp:templatefield>
<asp:templatefield headertext="Id" visible="False">
<itemtemplate>
<asp:label id="Label1" runat="server" text="<%# Eval("Id") %>"></asp:label>
</itemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Main Category">
<itemtemplate>
<asp:label id="Label2" runat="server" text="<%# Eval("Main_Category") %>"></asp:label>
</itemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Category">
</asp:templatefield></columns>
<pagerstyle cssclass="pgr"></pagerstyle>
</asp:gridview>
Then On RowCommand
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "select")
{
Session["Id"] = e.CommandArgument.ToString();
lblcategoryid.Text = Session["Id"].ToString();
getdata();
}
}
private void getdata()
{
String qry1 = "select * from Admin_Category_Software where Id='" + lblcategoryid.Text.ToString() + "'";
SqlDataAdapter da1 = new SqlDataAdapter(qry1, sconn);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count == 1)
{
if (sconn.State == ConnectionState.Open)
{
sconn.Close();
}
sconn.Open();
string query = "select * from Admin_Category_Software where Id='" + lblcategoryid.Text.ToString() + "'";
SqlCommand cmd = new SqlCommand(query, sconn);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
TextBox1.Text = dt.Rows[0][1].ToString();
cmd.ExecuteReader();
sconn.Close();
}
else
{
ScriptManager.RegisterStartupScript(this, typeof(string), "Alert", "alert('Record is Not Available');", true);
}
}