c# gridview中的RadioButtonList要怎么绑定数据源啊? 在线等~

来源:百度知道 编辑:UC知道 时间:2024/06/04 13:15:06
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" >
<Columns>···
<ItemTemplate>···
<asp:RadioButtonList ID="danxuan" runat="server" AutoPostBack="True" RepeatDirection="Horizontal"
Visible="False" Width="178%">
</ItemTemplate>···
是要绑定vot_op表里的op_id、op_name到RadioButtonList的DataValueField、DataTextField
我刚开始学,请大家帮忙啊~
linv2:sda.SelectCommand.Connection = con ;这句话报错了,“System.NullReferenceException: 未将对象引用设置到对象的实例。
”。我写的是:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString);
con.Open();
string strsql = null;
SqlDataAdap

RadioButtonList 在GridView1里边
你确定不是RadioButton?????
----------------------------------------------

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
SqlConnection mycon = new SqlConnection("数据库连接字符串");
string strsql=null;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand.Connection = mycon;
sda.SelectCommand.CommandText = strsql;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
RadioButtonList radlist = (RadioButtonList)GridView1.Rows[i].FindControl("RadioButtonList1");
DataTable tbl = new DataTable();
strsql = "SQL语句";
sda.Fill(tbl);
radlist.DataSource = tbl;
radlist.DataBind();
radlist.DataTextField = "op_name";
radlist.DataValueField = "op_id"