本文介绍了如何在按钮事件中找到gridview的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想找到对gridview itemtemplate的控制,我使用了下面的代码,但由于使用了
,所以我得到了值.for循环我仅获得最后一个值,例如,如果我需要第一行的值,则仅获得第二行的值,我将代码粘贴到此处,请帮助我怎么做
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
<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;
}
}
推荐答案
protected void lnkAssId_Click(object sender, EventArgs e)
{
string lnkAssId = (e.Item as GridDataItem).GetDataKeyValue("lnkAssId").ToString();
Session["AssId"] = lblAssId.Text;
}
使用这种方式而不是循环,您可以获取要在其上按的行的ID,然后可以通过该ID进行所需的操作
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
foreach (GridViewRow row in gridDelivery.Rows)
{
CheckBox checkPRNNo = (CheckBox)row.FindControl("checkPRNNo");
TextBox txtInvoiceno = (TextBox)row.FindControl("txtInvoiceno");
}
这篇关于如何在按钮事件中找到gridview的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!