ListItemCollection and getting value back from radiobuttonlist

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • casey

    ListItemCollection and getting value back from radiobuttonlist

    I am trying to bind a list collection with values to a
    radiobuttonlist , but when i try to access the
    selecteditem.va lue i always get the selecteditem.va lue


    private void Page_Load(objec t sender, System.EventArg s e)
    {
    // Put user code to initialize the page
    here
    if(!Page.IsPost Back)
    {
    ListItemCollect ion
    lictest = new ListItemCollect ion();
    ListItem li1 = new
    ListItem("1","1 aa");
    ListItem li2 = new
    ListItem("2","2 aa");

    lictest.Add(li1 );
    lictest.Add(li2 );

    RadioButtonList 1.DataSource = lictest;
    RadioButtonList 1.DataBind
    ();

    RadioButtonList 1.SelectedIndex = 0;
    string strTest =
    RadioButtonList 1.SelectedItem. Value.ToString( );
    //strTest always returns
    text instead of value
    }

    }
  • Guest's Avatar

    #2
    ListItemCollect ion and getting value back from radiobuttonlist

    Figured out a way around, by setting listitems directly
    to RadioButtonList 1.Items.Add(

    but still don't understand why you lose the Value part of
    a listItem when you bind a listitemCollect ion to a RBL

    hmmm

    casey

    [color=blue]
    >-----Original Message-----
    >I am trying to bind a list collection with values to a
    >radiobuttonlis t, but when i try to access the
    >selecteditem.v alue i always get the selecteditem.va lue
    >
    >
    >private void Page_Load(objec t sender, System.EventArg s e)
    > {
    > // Put user code to initialize the page
    >here
    > if(!Page.IsPost Back)
    > {
    > ListItemCollect ion
    >lictest = new ListItemCollect ion();
    > ListItem li1 = new
    >ListItem("1"," 1aa");
    > ListItem li2 = new
    >ListItem("2"," 2aa");
    >
    > lictest.Add(li1 );
    > lictest.Add(li2 );
    >
    > RadioButtonList 1.DataSource = lictest;
    > RadioButtonList 1.DataBind
    >();
    >
    > RadioButtonList 1.SelectedIndex = 0;
    > string strTest =
    >RadioButtonLis t1.SelectedItem .Value.ToString ();
    > //strTest always returns
    >text instead of value
    > }
    >
    > }
    >.
    >[/color]

    Comment

    Working...