Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i used grid view and loaded this by sql stored procedure using data table. i want to get first column value in every rows and pass this as a query string in hyperlink.
my code is....
.........
......
..
con.Open();
DataTable dt = new DataTable();

// SqlCommand cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
//SqlDataReader dr = cmd.ExecuteReader();
da.Fill(dt);
if (dt.Rows.Count > 0)
{

GridView1.DataSource = dt;
GridView1.DataBind();







HyperLinkField hfield = new HyperLinkField();
hfield.HeaderText = "Book ID"; hfield.NavigateUrl = "Issue_book.aspx?bid=";

hfield.DataTextField = dt.Columns[0].ToString();

GridView1.Columns.Add(hfield);
I want to pass "Book ID" as a query string in Issue_book.aspx?bid=
Posted
Updated 27-Jan-15 21:42pm
v2

1 solution

Simply write RowCommand Event for GridView like this

protected void gridView_RowCommand(object sender, GridViewCommandEventArgs e)
{

int rowId = int.Parse(e.CommandArgument.ToString());

if (e.CommandName == "linkbtn")//EditRow
{
string value = dtbVendorTargetDetails.Rows[rowId]["value"].ToString();
Response.Redirect("frmPage.aspx?code=" + value);
}

}
 
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