【问题标题】:How to use Radio Button in Repeater to retrieve data from sql?如何使用中继器中的单选按钮从 sql 中检索数据?
【发布时间】:2018-03-27 20:44:58
【问题描述】:

我在中继器中使用单选按钮,但在 C# 函数中我无法获取该单选按钮的 ID:

此 Asp 代码单选按钮与中继器中的组:

using (SqlDataReader dr = cmd.ExecuteReader())
{
    if (dr.HasRows)
    {
        while (dr.Read())
        {
            RadioButton1.Text = dr.GetString(5);
            RadioButton2.Text = dr.GetString(6);
            RadioButton3.Text = dr.GetString(7);
        }
    }
}

【问题讨论】:

  • 请删除图片并发布文本代码。

标签: c# asp.net radio-button repeater


【解决方案1】:

您知道您的 RadioButtns 在 Repeater 中,因此您必须使用 Foreach 循环将这些按钮文本从 Repeater 设置为:

foreach (RepeaterItem item in Repeater1.Items)
{
   // Check for data item or alternating item
   if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
   {
       // find your radiobutton from repeater's item
       RadioButton RadioButton1 = item.FindControl("RadioButton1") as RadioButton;

       RadioButton1.Text = dr.GetString(5);

       //.. some other code
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 2013-03-19
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多