美好的一天!
我的Gridview很难过。我使用的是C#.net和sql server。我想用gridview外面的按钮用单选按钮列表列中的数据更新我的gridview行。这是我的网格视图;
我想用单击按钮单击单选按钮列表中的选定值来更新列[rating]。
目前,我通过点击费率按钮并从网格视图上方的下拉列表中获取评级值来更新gridview列评级。
现在,我想知道是否有一种方法可以一键完成,并从gridview内的单选按钮列表中获取它的值。我的gridview代码在这里;
<p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onrowcommand="delete_enroll"
DataSourceID="training" Width="826px" AllowPaging="True" Visible="False"
style="text-align: center">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="deleterow" Text="CANCEL" />
<asp:ButtonField ButtonType="Button" CommandName="RATE" Text="RATE" />
<asp:BoundField DataField="Training_id" HeaderText="Training_id"
SortExpression="Training_id" />
<asp:BoundField DataField="User_id" HeaderText="User_id"
SortExpression="User_id" />
<asp:BoundField DataField="User_name" HeaderText="User_name"
SortExpression="User_name" />
<asp:BoundField DataField="Date_enrolled" HeaderText="Date_enrolled"
SortExpression="Date_enrolled" />
<asp:BoundField DataField="Rating" HeaderText="Rating"
SortExpression="Rating" />
<asp:TemplateField HeaderText="Rate">
<ItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Passed" Value="Passed"></asp:ListItem>
<asp:ListItem Text="Failed" Value="Failed"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</p>
任何帮助将不胜感激。谢谢!
答案 0 :(得分:0)
您可以在按钮单击事件处理程序中遍历gridview行,并像这样更新相应的行: -
protected void btnUpdate_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
RadioButtonList RadioButtonList1 = row.FindControl("RadioButto nList1")
as RadioButtonList;
row.Cells[6].Text = RadioButtonList1.SelectedValue;
}
}