Click here to Skip to main content
16,013,642 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is aspx.cs file code

protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["eid"] != null)
{
if (!Page.IsPostBack)
{
SqlDataAdapter da1 = new SqlDataAdapter("Select * from tbl_catinfo where cat_id = '" + Request.QueryString["eid"] + "'", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
txtID.Text = dt1.Rows[0][0].ToString();
txtCategory.Text = dt1.Rows[0][1].ToString();
ddlStatus.SelectedValue = dt1.Rows[0][2].ToString();
}
}
}

Here is aspx code
XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<pre lang="xml">&lt;asp:TemplateField HeaderText=&quot;Action&quot;&gt;

                &lt;ItemTemplate&gt;</pre>


 <a href="AddCategory.aspx?eid=<%# Eval("cat_id") %>"><img src="images/icon_edit.gif" alt="Edit" width="16" height="16" border="0"   /></a>
</ItemTemplate>
            </asp:TemplateField>

        </Columns>
    </asp:GridView>
Posted

1 solution

Hello Arpit,

The code behind in your case will look something like
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["eid"] != null)
    {
        if (!Page.IsPostBack)
        {
            SqlConnection sqlCon;
            SqlCommand sqlCmd;
            SqlDataReader sqlRdr;

             sqlCon = new SqlConnection();   
             sqlCon.ConnectionString = ConfigurationManager.ConnectionStrings["YOURDB"].ConnectionString;   
             sqlCmd = new SqlCommand();
             sqlCmd.CommandText = "SELECT * FROM tbl_catinfo WHERE cat_id = @cat_id";
             sqlCmd.Parameters.Add("@cat_id", Request.QueryString["eid"]);
             sqlCmd.Connection = sqlCon;
             sqlCmd.Connection.Open();
             sqlRdr = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
             GridView1.DataSource = sqlRdr;
             GridView1.DataBind();

             sqlCmd.Dispose();
             sqlCon.Dispose();
        }
    }
}

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900