Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I want to find control of the gridview itemtemplate I used the code below and i am getting the value but because of using the
for loop i am getting only the last value for instance if i need the value of the first row I am getting only the value of second row i am pasting my code here pl help me how to do it


C#
<asp:TemplateField HeaderText="Associate ID"> 
              <ItemTemplate> 
                <asp:LinkButton ID="lnkAssId" Text='<%# Eval("associate_id") %>' runat="server"  
                  onclick="lnkAssId_Click">LinkButton</asp:LinkButton> 
              </ItemTemplate> 
            </asp:TemplateField> 
  
  
protected void lnkAssId_Click(object sender, EventArgs e) 
  { 
    for (int i = 0; i < grdApproval.Rows.Count; i++) 
    { 
      LinkButton lblAssId = (LinkButton)grdApproval.Rows[i].FindControl("lnkAssId"); 
      Session["AssId"] = lblAssId.Text; 
    } 
    
  }
Posted

try this
protected void lnkAssId_Click(object sender, EventArgs e) 
  { 
string lnkAssId = (e.Item as GridDataItem).GetDataKeyValue("lnkAssId").ToString();
Session["AssId"] = lblAssId.Text;
}

using this way instead of looping you can get the id of the row you are pressing on it then you can do what do you want by this ID
 
Share this answer
 
Hi, Pls use below code, at button click event

foreach (GridViewRow row in gridDelivery.Rows)
            {
                CheckBox checkPRNNo = (CheckBox)row.FindControl("checkPRNNo");
                TextBox txtInvoiceno = (TextBox)row.FindControl("txtInvoiceno");
}
 
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