- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ASP.NET GridView,其中填充了数据、一个按钮和一个带有 4 个单选按钮的 RadioButtonList。如何通过按下 GridView 外部的按钮(使用 c# 代码隐藏)来获取选择的单选按钮?
GridView 内的按钮应用于删除一行(我认为是 RowCommand 事件...)
GridView 中的代码:
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" />
<asp:BoundField DataField="value" HeaderText="Value" />
<asp:TemplateField ShowHeader="false" HeaderText="Foo?">
<ItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="true">Item 1</asp:ListItem>
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="false" HeaderText="">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Remove" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
最佳答案
要了解选择了哪个 RadioButton,请按照当前代码中的以下步骤操作:
将您的按钮修改为:
<asp:TemplateField ShowHeader="false" HeaderText="">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Remove" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>"
CommandName="remove" />
</ItemTemplate>
</asp:TemplateField>
CommandName
和
CommandArgument
属性已填写。
CommandArgument
将行的索引传递给您的
RowCommand
事件。
RowCommand
事件看起来像这样:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "remove")
{
int index = Convert.ToInt32(e.CommandArgument);
if (index >= 0)
{
//index is the row, now obtain the RadioButtonList1 in this row
RadioButtonList rbl = (RadioButtonList)GridView1.Rows[index].FindControl("RadioButtonList1");
if (rbl != null)
{
string selected = rbl.SelectedItem.Text;
Response.Write("Row " + index + " was selected, radio button " + selected);
}
}
}
}
Value
给您的
RadioButtons
以便您检查值而不是文本。
关于c# - ASP 从 GridView 内的 RadioButtonList 读取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16109330/
出于好奇,任何人都知道内部实现的细节 ListControl.SelectedIndex = (int) 对比 ListControl.SelectedValue = .ToString() 我在使
首先,repeater with in a repeater可以用吗?如果是,我将如何在以下场景中使用嵌套中继器。
我创建了一个包含 2 个选项的选项列表:是和否,如下所示 radioButtonList($model,'active', array(1=>'Yes', 0=>'No'), array('separ
我有一个 ASP RadioButtonList,我想在客户端处理它。 该网页包含一个带有单选按钮组和关联的 GridView 的表单。当用户选择单选按钮之一时,我想隐藏或显示 GridView 上的
我有一个RadioButtonList,有两个选项:完整和部分。默认选择已满。 Full Partial 我还有一个 jquery 函数,它会导致某些元素在选择“部分”时隐藏,并
如何向 RadioButtonList 添加超链接? 我尝试了以下方法,但它仍然呈现为纯文本。 A"> B"> 我知道以下工作,但我想使用 RadioButtonList 而不是
我有一个单选按钮列表,其中包含更新搜索功能的 selectedindexchanged 事件。其中一项在 aspx 中指定,其他项是附加的数据绑定(bind)项。无论我将什么设置为默认值,该项目都不会
我正在 ASP.net 中创建一个注册 Web 表单,但在客户端发送空字符串,因为我选择了一个选项,其背后的原因是什么以及如何获得非空字符串。 这是我的 RadioButtonList 代码。
当我们在文本框中输入时,我需要使单选按钮列表可过滤。意思是如果我输入 M 然后应该显示 Music & Movie radio 。我想用 JS 或 jquery 来避免回发。我对他们两个都不太了解。
我想要一个单选按钮列表,您可以在其中选择值 null。 是这样的: '> RW R None 非常感谢,文森特 最佳答案 单选按钮
我有一个 DataList,它显示一些带有 RadioButtonList 的帖子,其中包含从 1 到 5 的 5 个选择,但是当我尝试获取 theRadioButtonList 的选定值时,它抛出空
我在 Web 表单上有一个 RadioButtonList 和一个提交按钮。当我单击具有空 RadioButtonList 值的提交按钮时,即没有从 RadioButtonList 中选择任何内容,我
我正在系统后端创建一个单选按钮列表。有什么方法可以让我以随机顺序显示项目吗? 我的代码: c# RadioButtonList1.Items.Add(New ListItem(rsQuestio
我正在寻找处理在 ASP.net RadioButtonList(后面的 C# 代码)上选择的索引更改的最佳方法。我有 3 个列表项。对于第一个,我希望它在页面上显示一个隐藏的 asp:textbox
基本上,我只想要 RadioButtonList 上没有单选按钮,我将对 rbl 进行编码,以便所选项目具有不同的背景颜色并使其看起来更专业,我希望能够摆脱单选按钮本身外观......如果你知道任何方
我有一个单选按钮列表,我需要在一些值之间添加标签。 我知道以下内容行不通,但这是我想在 .net 中执行的操作的最佳示例。 Regular
无论我在单选按钮列表上设置什么,它仍然呈现一个无序的垂直列表。 最佳答案 如果您碰巧正在使用 Sitefinity(就像我一样)
aspx 文件: ' DataSource='' Da
当我单击 ASP.NET 页面上的按钮控件时,我的单选按钮列表在回发后未选中地返回。
我似乎无法将 RadioButtonList 居中放置在面板中。它似乎总是有道理的。不管我怎么努力。 我目前的代码是:
我是一名优秀的程序员,十分优秀!