![](/img/trans.png)
[英]How to call method having parameters (object sender, EventArgs e )
[英]How to get row index from object sender, EventArgs e
我在asp.net页面上有一个DataList。 在数据列表的每一行上,我都有两个单选按钮(不是单选按钮列表)。 根据所按下的单选按钮,它们会在同一行上启用一些文本框并显示一些信息。 两个单选按钮都绑定到相同的事件处理程序。
我的问题是,如何知道单选按钮被按下时DataList的行号(索引)?
这是我的单选按钮事件处理程序的代码:
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
try
{
RadioButton radioBtn = (RadioButton)sender;
if (radioBtn.Checked == true)
{
switch (radioBtn.ID)
{
case "RadioButton1":
//Enable some textboxes
//Show some info - Need to display the row number of the Datalist where the Radio buttons were pressed
break;
case "RadioButton2":
//Disable some texboxes
break;
}
}
}
}
您可以使用NamingContainer获取父控件并获取其项目索引。
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
DataListItem item = (DataListItem)((RadioButtonList)sender).NamingContainer;
Label1.Text = item.ItemIndex.ToString();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.