本文介绍了如何在GridView ItemTemplate中找到控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想找到对itemtemplate中的linkbutton的控制,我使用了以下代码,并获取了值,但是由于使用了for循环,我仅获取了最后一个值,而先前的值也被清除了,这是我的代码pl告诉我如何获取正确的值
Hi
I want to find control of a linkbutton which is in the itemtemplate and I used the following code and i get the value but because of using the for loop I am getting only the last value and the previous values is getting cleared here is my code pl tell me how to get the correct value
<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>
for (int i = 0; i < grdApproval.Rows.Count; i++)
{
LinkButton lblAssId = (LinkButton)grdApproval.Rows[i].FindControl("lnkAssId");
Session["AssId"] = lblAssId.Text;
}
推荐答案
Session["AssId"] = Session["AssId"].ToString() + " " + lblAssId.Text;
或
Or
List<string> AssIds = new List<string>();
for (int i = 0; i < grdApproval.Rows.Count; i++)
{
LinkButton lblAssId = (LinkButton)grdApproval.Rows[i].FindControl("lnkAssId");
AssIds.Add(lblAssId.Text);
}
Sesion["AssId"] = AssIds;
然后使用foreach或for循环将列表中的所有值写入.
祝你好运,
OI
Then write all the values in the list with a foreach or for loop.
Good luck,
OI
这篇关于如何在GridView ItemTemplate中找到控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!