How to call control inside GridView
How to call control inside GridView without in GridView1_RowDeleting or SelectedIndexChanged or row command but call in user defined function to selected row for update or delete .
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 3, 2015, 9:37 PM EST
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
MyFuncation();
SqlCommand cmd = new SqlCommand("Delete From userTable (userName,age,birthPLace)");
GridView1.DataBind();
//Call any function that can perform delete operation based on value
}
private void MyFuncation()
{
//write your code here
}
Najim MullaRank #2,088 · 689 reputationPosted Mar 3, 2015, 9:39 PM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 3, 2015, 9:44 PM EST
//Third way
Najim MullaRank #2,088 · 689 reputationPosted Mar 3, 2015, 10:00 PM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 3, 2015, 10:18 PM EST
Don't use session use like
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int empId = Convert.ToInt32(grdEmp.DataKeys[e.RowIndex].Value);
MyFuncation(empId);
GridView1.DataBind();
//Call any function that can perform delete operation based on value
}
private void MyFuncation(int Id)
{
//write your code here
}
Najim MullaRank #2,088 · 689 reputationPosted Mar 3, 2015, 11:28 PM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 3, 2015, 11:33 PM EST
Try This
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
e.CommandArgument // Return Primary key
GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
row.Cells[0].///
row.Cells[1].///
................
}
}
Najim MullaRank #2,088 · 689 reputationPosted Mar 3, 2015, 11:40 PM EST