怎么在RadioButtonlist绑定数据库中的图片后设置默认选择第一项
如何在RadioButtonlist绑定数据库中的图片后设置默认选择第一项
试过了不管用。
因为是绑定的数据库,在Items里是没有东西的。
还有我的RadioButtonlist绑定的是数据库中的图片的地址,然后用
SELECT PARTY_CODE, '<img src=' + PARTY_ICON + '>' AS PARTYPATH FROM PARTY
显示图片。
运行效果是这样的
怎样让它默认选择第一项呢?
请各位大神帮帮忙啊。
------解决方案--------------------
不是在Page_Load里进行数据绑定,是在RadioButtonList里的ondatabound事件内绑定
前台代码:
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
this.RadioButtonList1.Items[0].Selected = true;
}
试过了不管用。
因为是绑定的数据库,在Items里是没有东西的。
还有我的RadioButtonlist绑定的是数据库中的图片的地址,然后用
SELECT PARTY_CODE, '<img src=' + PARTY_ICON + '>' AS PARTYPATH FROM PARTY
显示图片。
运行效果是这样的
怎样让它默认选择第一项呢?
请各位大神帮帮忙啊。
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();
}