我正在使用C#开发一个应用程序。我在TreeView中使用RadioButtonlist控件。我正在从数据库中收集项目。根据收集项目,我需要选择Radiobuttonlist项目。
例如,从数据库中我以这种方式获得了Collection:Read(R)Write(W)
基于此收集我需要设置用户权限。
答案 0 :(得分:0)
如果我的问题正确,您希望根据网格上的当前行项基于数据库中的项绑定该radiobutton列表。如果是这样的情况就是你的解决方案。
假设您有一个名为myGrid的Grid,一个名为myRadio的RadioButtonList和一个名为myHidden的HiddenField(这是您绑定“R”和“W”的值的地方)
所有你需要做的就是当一个RowDataBound事件发生时你必须将值赋给myRadio
例如,你有一个像这样的
的RadioButtonList<asp:RadioButtonList ID="myRadio" runat="server">
<asp:ListItem Value="R">Read</asp:ListItem>
<asp:ListItem Value="W">Write</asp:ListItem>
</asp:RadioButtonList>
所以你的代码背后应该是这样的
protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButtonList rdoAnswer = (RadioButtonList)e.Row.FindControl("myRadio");
HiddenField hdnValue = (HiddenField)e.Row.FindControl("myHidden");
rdoAnswer.SelectedValue = hdnValue.Value;
}
}