Question

I have this problem : But i cloudn't convert the radiobuttonlist value to id

i have to insert the giving value or text in the id colum in my table.

 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>

Code Behind File:

 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)); 
      } 
    }

i tried a lot of things but it keeps giving me errors so i gave up. However it says cannot convert from string to int.

Datatype : System.Int32 i need to get the number as the id's

Was it helpful?

Solution

i think you are using Text Poperty of RadioButtonList , Use Value for getting the ID value as below:

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

while passing parameters you can pass intID as argument :

Replace this :

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

With following:

InsertPhotoInfo.InsertPhoto(TextBox1.Text, TextBox2.Text, TextBox3.Text,intID);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top