110,571
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRadioList();
}
}
//绑定radiolist
private void BindRadioList()
{
this.RadioButtonList1.DataSource = ds.Tables[0];
this.RadioButtonList1.DataTextField = "字段1";
this.RadioButtonList1.DataValueField = "字段2";
this.RadioButtonList1.DataBind();
this.RadioButtonList1.SelectedIndex = 0;
}
protected void Button1_Click(object sender, EventArgs e)
{
string text = this.RadioButtonList1.SelectedItem.Text.ToString();
string value = this.RadioButtonList1.SelectedValue.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadioButtonList1.DataSource = getTable();
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "ID";
RadioButtonList1.DataBind();
RadioButtonList1.SelectedIndex = 0;
}
}
public DataTable getTable()
{
string[] name = { "张三", "李四", "王五", "赵六" };
DataTable dt = new DataTable("");
dt.Columns.Add("ID", typeof(System.Int32));
dt.Columns.Add("Name", typeof(System.String));
dt.Columns.Add("Number", typeof(System.Double));
for (int i = 0; i < name.Length; i++)
{
DataRow row = dt.NewRow();
row[0] = i + 1;
row[1] = name[i];
row[2] = 12.3;
dt.Rows.Add(row);
}
return dt;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(RadioButtonList1.SelectedItem.Text.ToString());
Response.Write(RadioButtonList1.SelectedValue);
}
if (this.selectdatatable().Rows.Count > 0)
{
this.RadioButtonList1.DataSource = GetTabelBySql();
this.RadioButtonList1.DataTextField = "ExcelFile";
this.RadioButtonList1.DataValueField = "ExcelPath";
this.RadioButtonList1.DataBind();
RadioButtonList1.SelectedIndex = 0;
}
RadioButtonList1.DataSource = GetTable();
RadioButtonList1.DataTextField = "ExcelFile";
RadioButtonList1.DataValueField = "ExcelPath";
RadioButtonList1.DataBind();
RadioButtonList1.SelectedIndex = 0;
<td colspan="2" style="width:900px">
<asp:Panel ID="pnlExcel" runat="server" ScrollBars="Vertical" Height="100px" BorderStyle="Dotted" BorderColor="Gray">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" >
</asp:RadioButtonList>
</asp:Panel>
</td>
<td><asp:Button ID="Button1" runat="server" Text="选择" Width="75px"
onclick="Button1_Click"/></td>
</tr>