【问题标题】:RadioButtonList Convert the value to int as(id)RadioButtonList 将值转换为 int as(id)
【发布时间】:2013-11-10 12:45:05
【问题描述】:

我有这个问题: 但我没有将单选按钮列表值转换为 id

我必须在表格的 id 列中插入给定值或文本。

 PhotoTableAdapter InsertPhotoInfo = new PhotoTableAdapter();
            InsertPhotoInfo.InsertPhoto(TextBox1.Text, TextBox2.Text, TextBox3.Text, RadioButtonList1.Text);

  <asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="horizontal" RepeatLayout="Table" CssClass="rdo" runat="server">
        <asp:ListItem Text="1" Value="1">Black</asp:ListItem>
        <asp:ListItem Text="2" Value="2">Archi</asp:ListItem>
        <asp:ListItem Text="3" Value="3">Qu</asp:ListItem>
        <asp:ListItem Text="4" Value="4">Fun</asp:ListItem>
        <asp:ListItem Text="5" Value="5"> Fash</asp:ListItem>
        <asp:ListItem Text="6" Value="6">Peo</asp:ListItem>
        <asp:ListItem Text="7" Value="7">Land</asp:ListItem>
        <asp:ListItem Text="8" Value="8">City</asp:ListItem>
        <asp:ListItem Text="9" Value="9">Transport</asp:ListItem>

    </asp:RadioButtonList>

文件背后的代码:

 protected void Button1_Click(object sender, EventArgs e)
     { 
    String radioID = RadioButtonList1.Items[0].Value.ToString();
    int intID = Convert.ToInt32(radioID);
     { 
      PhotoTableAdapter InsertPhotoInfo = new PhotoTableAdapter();
  InsertPhotoInfo.InsertPhoto(TextBox1.Text, TextBox2.Text, TextBox3.Text,RadioButtonList1.radioID)); 
      } 
    }

我尝试了很多东西,但它一直给我错误,所以我放弃了。 但是它说不能从字符串转换为整数。

数据类型:System.Int32 我需要获取数字作为 id 的

【问题讨论】:

    标签: c# string dataset int radiobuttonlist


    【解决方案1】:

    我认为您正在使用 RadioButtonListText Poperty ,使用 Value 获取 ID 值如下:

    String radioID=RadioButtonList1.SelectedValue.ToString()   
    int intID=Convert.ToInt32(radioID);
    

    在传递参数时,您可以将intID 作为参数传递:

    替换这个:

    InsertPhotoInfo.InsertPhoto(TextBox1.Text, TextBox2.Text, TextBox3.Text,RadioButtonList1.radioID));
    

    以下:

    InsertPhotoInfo.InsertPhoto(TextBox1.Text, TextBox2.Text, TextBox3.Text,intID);
    

    【讨论】:

    • 这是我迄今为止尝试过的,但它说需要标识符。 protected void Button1_Click(object sender, EventArgs e) { String radioID = RadioButtonList1.Items[0].Value.ToString(); int intID = Convert.ToInt32(radioID); { PhotoTableAdapter InsertPhotoInfo = new PhotoTableAdapter(); InsertPhotoInfo.InsertPhoto(TextBox1.Text, TextBox2.Text, TextBox3.Text,RadioButtonList1.(radioID)); } }
    • 我正在尝试将单选项目值插入 id 列。
    • 我没有让你感到抱歉,你能给我举个例子吗?
    • 我应该如何将它实际添加到我的代码中?如您所见,我的代码。
    • 请使用上面不可读的代码编辑您的帖子/问题。
    猜你喜欢
    • 2013-08-13
    • 1970-01-01
    • 2021-11-04
    • 2017-06-26
    • 1970-01-01
    • 2015-04-30
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多