读书人

怎么在RadioButtonlist绑定数据库中的

发布时间: 2013-06-26 14:29:32 作者: rapoo

如何在RadioButtonlist绑定数据库中的图片后设置默认选择第一项


怎样让它默认选择第一项呢?
请各位大神帮帮忙啊。 RadioButtonlist 数据库 图片
[解决办法]
不是在Page_Load里进行数据绑定,是在RadioButtonList里的ondatabound事件内绑定
前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" DataSourceID="SqlDataSource1"
DataTextField="test1" DataValueField="id"
ondatabound="RadioButtonList1_DataBound">
</asp:RadioButtonList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:sqlTestConnectionString %>"
SelectCommand="select id,'<img src=/1/'+url+'>' as test1 from Table_3"></asp:SqlDataSource>
</div>
</form>
</body>
</html>

后台代码:
        protected void Page_Load(object sender, EventArgs e)
{

//RadioButtonList1.DataSource = TM.DBUtility.DbHelperSQL.GetDataTable("select id,'<img src=/1/'+url+'>' as test1 from Table_3");
//RadioButtonList1.DataTextField = "test1";
//RadioButtonList1.DataValueField = "id";
//RadioButtonList1.DataBind();
}



protected void RadioButtonList1_DataBound(object sender, EventArgs e)
{
RadioButtonList1.Items[0].Selected = true;
}


成功效果图:怎么在RadioButtonlist绑定数据库中的图片后设置默认选择第一项

读书人网 >asp.net

热点推荐