msreekm
asked on
radiobuttonlist datavaluefield and ckecked
I have a dradiobuttonlist control inside repeater some sort of survey form, when iam selecting some radio and doing a post back ny cliking an image button , all first radio buttons in the list get selected irrespective of which radio button is being choosen?? i have cjecked page.ispostback while binding. any thing else???
<ASP:REPEATER id="MyRepeater" runat="server" EnableViewState="True">
<HeaderTemplate>
<table border="1" width="100%">
<tr><th colspan="3" align="left">
<div class="sectionHeader">
<IMG class="markerWide" src="images/mO.gif"> Feedback Form
</div></th>
<th>
<b>Comments</b></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<b<%# DataBinder.Eval(Container. DataItem, "SERVICE_NAME") %></b></td>
<td>
<asp:RadioButtonList id="rb" RepeatDirection =Horizontal DataSource='<%#GetChoices( (string)Da taBinder.E val(Contai ner.DataIt em,"SERVIC E_NAME"))% >' DataTextField="CODE"
DataValueField="SERVICE"
CssClass="INPUT.radio" runat="server">
</asp:RadioButtonList>
</td<td>
<td align="center">
<asp:TextBox ID='<%#DataBinder.Eval(Con tainer.Dat aItem,"SER VICE_NAME" )%>' Runat="server"></asp:TextB ox>
</td>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate></ASP:REP EATER>
<ASP:REPEATER id="MyRepeater" runat="server" EnableViewState="True">
<HeaderTemplate>
<table border="1" width="100%">
<tr><th colspan="3" align="left">
<div class="sectionHeader">
<IMG class="markerWide" src="images/mO.gif"> Feedback Form
</div></th>
<th>
<b>Comments</b></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<b<%# DataBinder.Eval(Container.
<td>
<asp:RadioButtonList id="rb" RepeatDirection =Horizontal DataSource='<%#GetChoices(
DataValueField="SERVICE"
CssClass="INPUT.radio" runat="server">
</asp:RadioButtonList>
</td<td>
<td align="center">
<asp:TextBox ID='<%#DataBinder.Eval(Con
</td>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate></ASP:REP
Hi,
can you paste some code here?
Regards,
Venki
can you paste some code here?
Regards,
Venki
ASKER
i have already posted the code...
ASKER
i was trying this little bit of code...
<< page_load....>>
if(!Page.IsPostBack)
{
ArrayList Person = new ArrayList();
Person.Add(new Person("sree",23));
Person.Add(new Person("sreekumar",231));
Repeater1.DataSource=Perso n;
Repeater1.DataBind();
}
}
public ArrayList getSex(string name)
{
ArrayList Personsex = new ArrayList();
Personsex.Add(new Personsex(name,"Male",1));
Personsex.Add(new Personsex(name,"Female",2) );
return Personsex;
}
}
more code here...
----------
class Person
{
string _name;
int _id;
public string name
{
get
{
return _name;
}
set
{
_name=value;
}
}
public int id
{
get
{
return _id;
}
set
{
_id=value;
}
}
public Person(string name,int id)
{
_name=name;
_id=id;
}
}
-----
class Personsex
{
string _myname;
string _sex;
int _age;
public string name
{
get
{
return _myname;
}
set
{
_myname=value;
}
}
public string sex
{
get
{
return _sex;
}
set
{
_sex=value;
}
}
public int age
{
get
{
return _age;
}
set
{
_age=value;
}
}
public Personsex(string myname,string sex,int age)
{
_myname=myname;
_sex=sex;
_age=age;
}
}
-------------------------- ------
What I am trying to achieve is display list of names and list of sex against them. even though this is not a real life requirement I am trying to simplify things here to explain my problem. somthing
like
name1 male O female O
name2 male O female O
name3 male O female O
name4 male O female O
0->radio button
now for the partial aspx code...
<form id="Form1" method="post" runat="server">
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Contain er.DataIte m, "name") %>
<br />
<asp:RadioButtonList id="radiolist1" runat="server"
DataSource='<%#getSex((str ing)DataBi nder.Eval( Container. DataItem," name"))%>'
DataTextField="sex"
DataValueField="name"
>
</asp:RadioButtonList>
</ItemTemplate>
</asp:Repeater>
<asp:Button text="Submit" runat="server" ID="Button1" />
<p>
<asp:Label id="Label1" runat="server" /></p>
</form>
I want to pass the name from the repeater1 to the radiobuttons and put in DataValueField field, or else how will i identify the options??? now when iam using age as value it works ,when i change it to name ,doesnt work as expected... is this the right way??? or any better way to achieve this???
From: sreekumar menon
<< page_load....>>
if(!Page.IsPostBack)
{
ArrayList Person = new ArrayList();
Person.Add(new Person("sree",23));
Person.Add(new Person("sreekumar",231));
Repeater1.DataSource=Perso
Repeater1.DataBind();
}
}
public ArrayList getSex(string name)
{
ArrayList Personsex = new ArrayList();
Personsex.Add(new Personsex(name,"Male",1));
Personsex.Add(new Personsex(name,"Female",2)
return Personsex;
}
}
more code here...
----------
class Person
{
string _name;
int _id;
public string name
{
get
{
return _name;
}
set
{
_name=value;
}
}
public int id
{
get
{
return _id;
}
set
{
_id=value;
}
}
public Person(string name,int id)
{
_name=name;
_id=id;
}
}
-----
class Personsex
{
string _myname;
string _sex;
int _age;
public string name
{
get
{
return _myname;
}
set
{
_myname=value;
}
}
public string sex
{
get
{
return _sex;
}
set
{
_sex=value;
}
}
public int age
{
get
{
return _age;
}
set
{
_age=value;
}
}
public Personsex(string myname,string sex,int age)
{
_myname=myname;
_sex=sex;
_age=age;
}
}
--------------------------
What I am trying to achieve is display list of names and list of sex against them. even though this is not a real life requirement I am trying to simplify things here to explain my problem. somthing
like
name1 male O female O
name2 male O female O
name3 male O female O
name4 male O female O
0->radio button
now for the partial aspx code...
<form id="Form1" method="post" runat="server">
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Contain
<br />
<asp:RadioButtonList id="radiolist1" runat="server"
DataSource='<%#getSex((str
DataTextField="sex"
DataValueField="name"
>
</asp:RadioButtonList>
</ItemTemplate>
</asp:Repeater>
<asp:Button text="Submit" runat="server" ID="Button1" />
<p>
<asp:Label id="Label1" runat="server" /></p>
</form>
I want to pass the name from the repeater1 to the radiobuttons and put in DataValueField field, or else how will i identify the options??? now when iam using age as value it works ,when i change it to name ,doesnt work as expected... is this the right way??? or any better way to achieve this???
From: sreekumar menon
ASKER
Number and values of radio buttons are dynamic . In actual I would be getting the values from database and storing the selected option back..
Regards
Sree
Regards
Sree
ASKER
I figured out the problem here... I had multiple items with the same value in the datavaluefield property. When a user clicked a choice, it grabbed the first option in the list. I changed the datavaluefield to a unique ID and all is well. I thought that multiple list items could have the same value...
anyways thanks for the replies...
Sree
anyways thanks for the replies...
Sree
ASKER
no points ? I thought the code given was helpful for him...
-Sree
-Sree
ASKER
sorry i meant since nobody really helped me , no points are to given . it should be refunded
Thanks
Sree
Thanks
Sree
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER