在datagrid中用radiobuttonlist邦定数据表中的数列
哪位能帮个忙,怎样把数据表中的几列邦定到radiobuttonlist的不同listitem中? 问题点数:100、回复次数:3Top
1 楼zhongkeruanjian(编程亮子)回复于 2006-03-04 21:10:26 得分 0
不需要用radiobuttonlist
直接用RadioButton ,然后给一个groupname就行了,效果是一样Top
2 楼cat_hsfz(我的新Blog在http://cathsfz.cnblogs.com)回复于 2006-03-05 00:01:04 得分 0
你继承RadioButtonList,添加几个Bindable的属性,这几个属性是直接操作List中的RadioButton的对应属性的。然后就把你这个继承类放到DataGrid中,把你要的几个列都Bind到那几个你添加的属性上,那就相当于Bind到那里面的几个RadioButton上了。Top
3 楼wys4534(草地恋)回复于 2006-03-05 10:44:28 得分 0
我想在datagrid中用模板列中的radiobuttonlist实现对数据表中的一行数列的数据实现单选,在界面的模板中用如下语句绑定:
<asp:datagrid id="dg3" style="Z-INDEX: 111; LEFT: 216px; POSITION: absolute; TOP: 224px" runat="server"
Width="456px" Height="126px" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="prid" HeaderText="题号"></asp:BoundColumn>
<asp:BoundColumn DataField="prtext" HeaderText="题干"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:RadioButtonList ID="xx" Runat="server" OnSelectedIndexChanged="selchange">
<asp:ListItem Value="a"></asp:ListItem>
<asp:ListItem Value="b"></asp:ListItem>
<asp:ListItem Value="c"></asp:ListItem>
<asp:ListItem Value="d"></asp:ListItem>
<asp:ListItem Value="e"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
在后台代码中用如下两个函数作进一步绑定,但我不知如何绑定不同listitem的datafield,所以下面的代码只绑定了一行,但也没有实现,我不知错在那里,请各位指点:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim strsql As String
strsql = "select * from worpr2作业多选表 where prid=" + "'" + Session("prid") + "'"
Dim adp As New System.Data.SqlClient.SqlDataAdapter(strsql, strconnection)
Dim objds As New DataSet
adp.Fill(objds, "dt1")
dg3.DataSource = objds.Tables("dt1")
dg3.DataBind()
End If
End Sub
Private Sub dg3_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg3.ItemDataBound
objconnection.Open()
Dim strsql As String
strsql = "select sela,seab,selc,seld,sele from worpr2作业多选表 where prid=" + "'" + Session("prid") + "'"
Dim cmd As New System.Data.SqlClient.SqlCommand(strsql, objconnection)
'r.DataTextField = "sectionname"
'r.DataValueField = "sectionID"
Dim r As System.Web.UI.WebControls.RadioButtonList
If e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.SelectedItem Then
Dim i As Int16
' For i = 0 To e.Item.Cells.Count - 1
If e.Item.Cells(2).Controls.Count > 0 Then
If e.Item.Cells(2).Controls(0).GetType().ToString() = "System.Web.UI.WebControls.RadioButtonList" Then
r = CType(e.Item.Cells(2).Controls(0), RadioButtonList)
r.Items.Add("sela")
r.DataTextField = "sela"
r.DataValueField = "a"
r.DataSource = cmd.ExecuteReader
r.DataBind()
End If
End If
' Next
End If
objconnection.Close()
End SubTop




