C# ASP.NET Repeater控件-获取Repeater控件内的Hiddenfield值
我在中继器控件内有一个hiddenfield,在中继器控件外有一个按钮。下面是我的asp.NET代码C# ASP.NET Repeater控件-获取Repeater控件内的Hiddenfield值,c#,asp.net,accordion,repeater,hidden-field,C#,Asp.net,Accordion,Repeater,Hidden Field,我在中继器控件内有一个hiddenfield,在中继器控件外有一个按钮。下面是我的asp.NET代码 类别目标: 类别风险评分: % 添加问题 您必须获取中继器项才能访问隐藏字段: protected void btnInsertQuestion_Click(object sender, EventArgs e) { for (int i = 0; i < rptAccordian.Items.Count; i++)
类别目标:
类别风险评分:
%
添加问题
您必须获取中继器项才能访问隐藏字段:
protected void btnInsertQuestion_Click(object sender, EventArgs e)
{
for (int i = 0; i < rptAccordian.Items.Count; i++)
{
var item = rptAccordian.Items[i];
var hf = item.FindControl("hdnCategoryID") as HiddenField;
var val = hf.Value;
}
}
你不需要使用hiddenfield就可以得到它。您需要像这样声明中继器中的
Add
LinkButton
protected void Add_Click(object sender, EventArgs e)
{
//Get the reference of the clicked button.
LinkButton button = (sender as LinkButton );
//Get the command argument
string cat_id = button.CommandArgument;
// Type cast to int if application and use it.
}
OnClick=“添加”>添加问题
您已经为btn插入问题
按钮单击编写了代码,您要求在添加按钮单击中获取CategoryID
,因此我假设您的要求是正确的,但您键入了其他内容
要在“添加”按钮单击中获取CategoryId,您需要这样写
protected void Add_Click(object sender, EventArgs e)
{
//Get the reference of the clicked button.
LinkButton button = (sender as LinkButton );
//Get the command argument
string cat_id = button.CommandArgument;
// Type cast to int if application and use it.
}
我已经使用jQuery获得了我的答案。我使用jQuery找到了控件hdnCategoryID及其值,并将该值指定给一个新的隐藏字段,然后将该值检索到我的单击事件。使用此链接将非常有用。您正在寻找一个id为“hiddenid”的HiddenField
,但aspx中的实际id是“hdnCategoryID”。您好,请使用您的代码进行尝试。但是,我在for(int i=0;i