|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Assign database value to a RadioButtonList controlRadioButtonList control. On my form i have 3 user admin=1, premium=2 and basic=3, theese values is stored in an access database in a text string. My problem is that when i'm loading my form, it uses a repeater control for each user by the way, I can't find a way to assign either of these values to the RadioButtonList Control. I can read them from the database but i wan't the ListItem to be set checked correct for each user...here is some code... *.aspx form .... <asp:RadioButtonList ID="rdbtlstLevel" RepeatDirection="Vertical" ToolTip="Admin" runat="server"> <asp:ListItem Value=1>Admin</asp:ListItem> <asp:ListItem Value=2>Premium</asp:ListItem> <asp:ListItem Value=3>Basic</asp:ListItem> </asp:RadioButtonList> ..... *.cs form .... this.rpUser.DataSource = objDS.Tables["tblOrganisation"].DefaultView; switch (objDS.Tables["tblOrganisation"].Rows["Level"].ToString()) { case "1": this.rdbtlstLevel.Items[0].Selected = true; break; case "2": this.rdbtlstLevel.Items[1].Selected = true; break; case "3": this.rdbtlstLevel.Items[2].Selected = true; break; } this.rpUser.DataBind(); .... Hence what I wan't to do is to get the values 1,2,3 from access, transform them to either true or false and then set The correct ListItem to checked on the *.aspx form for each user. Any hint from someone?? //Michael Hi,
Although, I did nt get your problem exactly, But according to what I get .. If you want to place a RadioButtonList in Itemptemplate of a repeater..... and in one columen of that repeater you are showing 3 values at RBList ... Then you should use Bind the RadioButtoList in same fasion as we use in case of parent child DataGrid Or Repeater.. ..although in your case you dont have parent child tables to get data. Because, You want to show 3 values in one control angain one record. i.e for RadioButtonList you need to use ItemDataBound Event As is used in following example to bind a nested repeater In your case instead of getting child rows .. just get the current row and the string containing ur data .. make it an array and bind to the RBList. http://www.mostlylucid.co.uk/articles/nestedrepeaters.htm I mean you can Show quoteHide quote "Michael Bohman" <michael_boh***@telia.com> wrote in message news:4jEPf.47554$d5.204206@newsb.telia.net... > Hi, i have a small problem with assigning a database value to a > RadioButtonList control. On my form i have 3 user admin=1, premium=2 and > basic=3, theese values is stored in an access database in a text string. > > My problem is that when i'm loading my form, it uses a repeater control > for each user by the way, I can't find a way to assign either of these > values to the RadioButtonList Control. I can read them from the database > but i wan't the ListItem to be set checked correct for each user...here is > some code... > > *.aspx form > ... > <asp:RadioButtonList ID="rdbtlstLevel" RepeatDirection="Vertical" > ToolTip="Admin" runat="server"> > <asp:ListItem Value=1>Admin</asp:ListItem> > <asp:ListItem Value=2>Premium</asp:ListItem> > <asp:ListItem Value=3>Basic</asp:ListItem> > </asp:RadioButtonList> > .... > > *.cs form > ... > this.rpUser.DataSource = objDS.Tables["tblOrganisation"].DefaultView; > switch (objDS.Tables["tblOrganisation"].Rows["Level"].ToString()) > { > > case "1": this.rdbtlstLevel.Items[0].Selected = true; > break; > case "2": > this.rdbtlstLevel.Items[1].Selected = true; > break; > case "3": > this.rdbtlstLevel.Items[2].Selected = true; > break; > } > this.rpUser.DataBind(); > ... > > Hence what I wan't to do is to get the values 1,2,3 from access, transform > them to either true or false and then set The correct ListItem to checked > on the *.aspx form for each user. > > Any hint from someone?? > > //Michael Munawar Hussain skrev:
Show quoteHide quote > Hi, You're hint made me realize my mistake, In the *.aspx file i have to > Although, I did nt get your problem exactly, But according to what I get .. > > If you want to place a RadioButtonList in Itemptemplate of a repeater..... > and in one columen of that repeater you are showing 3 values at RBList ... > Then you should use Bind the RadioButtoList in same fasion as we use in case > of parent child DataGrid Or Repeater.. ..although in your case you dont have > parent child tables to get data. > > Because, You want to show 3 values in one control angain one record. > > i.e for RadioButtonList you need to use ItemDataBound Event As is used in > following example to bind a nested repeater > In your case instead of getting child rows .. just get the current row and > the string containing ur data .. make it an array and bind to the RBList. > > http://www.mostlylucid.co.uk/articles/nestedrepeaters.htm > > > I mean you can > "Michael Bohman" <michael_boh***@telia.com> wrote in message > news:4jEPf.47554$d5.204206@newsb.telia.net... >> Hi, i have a small problem with assigning a database value to a >> RadioButtonList control. On my form i have 3 user admin=1, premium=2 and >> basic=3, theese values is stored in an access database in a text string. >> >> My problem is that when i'm loading my form, it uses a repeater control >> for each user by the way, I can't find a way to assign either of these >> values to the RadioButtonList Control. I can read them from the database >> but i wan't the ListItem to be set checked correct for each user...here is >> some code... >> >> *.aspx form >> ... >> <asp:RadioButtonList ID="rdbtlstLevel" RepeatDirection="Vertical" >> ToolTip="Admin" runat="server"> >> <asp:ListItem Value=1>Admin</asp:ListItem> >> <asp:ListItem Value=2>Premium</asp:ListItem> >> <asp:ListItem Value=3>Basic</asp:ListItem> >> </asp:RadioButtonList> >> .... >> >> *.cs form >> ... >> this.rpUser.DataSource = objDS.Tables["tblOrganisation"].DefaultView; >> switch (objDS.Tables["tblOrganisation"].Rows["Level"].ToString()) >> { >> >> case "1": this.rdbtlstLevel.Items[0].Selected = true; >> break; >> case "2": >> this.rdbtlstLevel.Items[1].Selected = true; >> break; >> case "3": >> this.rdbtlstLevel.Items[2].Selected = true; >> break; >> } >> this.rpUser.DataBind(); >> ... >> >> Hence what I wan't to do is to get the values 1,2,3 from access, transform >> them to either true or false and then set The correct ListItem to checked >> on the *.aspx form for each user. >> >> Any hint from someone?? >> >> //Michael > > Hi Munawar change the line for the RadioListButton Select index to 'SelectedIndex=<%#Convert.ToInt16(DataBinder.Eval(Container.DataItem,"Niva"))' Now everything works great, thanks! //Michael |
|||||||||||||||||||||||