Cross tab, DataGrid, Templates

E

Eric Caron

Hi everyone,

I have a web form that asks the user what languages he speaks and what his
skill level is. I used a DataGrid control bound to a table that contains
the languages and three template columns (beginner, intermediate, expert)
that contain a radio button control. Now, only one skill level can be
selected per language, so I tried to give the same name to the radio button
control. When the page loads for the first time, everything is fine, but
when there is a postback, I get an error message saying that the id for the
radio button must not be the same for the FindControl function to work.

How can I do this differently?
 
E

Eric Caron

Hi Scott,

Here's the DataGrid layout:

<asp:datagrid id="dgLangues" runat="server" CssClass="list" Width="70%"
CellSpacing="1" AutoGenerateColumns="False" GridLines="None"
HorizontalAlign="Center" CellPadding="4">
<SelectedItemStyle CssClass="listselected"></SelectedItemStyle>
<EditItemStyle CssClass="listedit"></EditItemStyle>
<AlternatingItemStyle CssClass="list2"></AlternatingItemStyle>
<ItemStyle CssClass="list1"></ItemStyle>
<HeaderStyle BorderStyle="Solid" CssClass="listheader"></HeaderStyle>
<FooterStyle CssClass="listfooter"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="LangueNom" HeaderText="Langue(s)">
<HeaderStyle Width="25%"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Niveau élémentaire">
<HeaderStyle HorizontalAlign="Center" Width="25%"
VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<P align="center">
<asp:RadioButton id="radNiveauLangue"
runat="server"></asp:RadioButton></P>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"
VerticalAlign="Middle"></FooterStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Niveau intermédiaire">
<HeaderStyle HorizontalAlign="Center" Width="25%"
VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:RadioButton id="radNiveauLangue" runat="server"></asp:RadioButton>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"
VerticalAlign="Middle"></FooterStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Niveau avancé">
<HeaderStyle HorizontalAlign="Center" Width="25%"
VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:RadioButton id="radNiveauLangue" runat="server"></asp:RadioButton>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"
VerticalAlign="Middle"></FooterStyle>
</asp:TemplateColumn>
</Columns>
<PagerStyle CssClass="listpager"></PagerStyle>
</asp:datagrid>

Another related question, how can I save the ID of each row in my datagrid?
 
S

Scott Allen

Hi Scott,

Here's the DataGrid layout:

Ah, so you have multiple radio buttons in each row. In this case you
do need to give each radio button control a unique id. Like
radNiveauLangueBeginner, radNiveauLangueAdvanced (sorry, my french is
rusty). If you call FindControl("radNiveauLangueBeginner") on each row
(a DataGridItem, to be precise), FindControl will be able to find each
control then.
Another related question, how can I save the ID of each row in my datagrid?

One way is to use the DataKeyField and DataKeys property of the grid.

HTH,
 
E

Eric Caron

Hi Scott,

This is the way I had done it in the first place, but I need to select only
one language skill level per row. Is there a way to do this without doing a
postback? Using ASP 3.0, I would have generated each row using a name built
using the ID of the language, but I would have used the same name for all
three columns. Now, do I have to write a messy javascript function to keep
track of all those radio buttons? And even so, I don't even know where to
begin...

Can I somehow generate the name/id of the radio button control while binding
the datagrid? Is there another template control that would do a better job
for this kind of situation?

Thanks for your help!
 
S

Scott Allen

Hi Eric:

If understand what you are trying to do, perhaps you want to fall back
to HTML elements and avoid the server side radio button control. Then
you can name then what you would like and handle them with javascript.

--s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top