Cross tab, DataGrid, Templates

Discussion in 'ASP .Net' started by Eric Caron, Sep 30, 2004.

  1. Eric Caron

    Eric Caron Guest

    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?
    Eric Caron, Sep 30, 2004
    #1
    1. Advertising

  2. Eric Caron

    Scott Allen Guest

    Hi Eric:

    >"I tried to give the same name to the radio button
    >control."


    Can you give an show us your template columns?

    The DataGrid should automatically provide unique names for the server
    controls inside. See my article for some tips and details:

    In Search of ASP.NET Controls
    http://odetocode.com/Articles/116.aspx

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Thu, 30 Sep 2004 14:25:08 -0400, "Eric Caron"
    <> wrote:

    >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?
    >
    Scott Allen, Sep 30, 2004
    #2
    1. Advertising

  3. Eric Caron

    Eric Caron Guest

    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?

    "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    news:...
    > Hi Eric:
    >
    > >"I tried to give the same name to the radio button
    > >control."

    >
    > Can you give an show us your template columns?
    >
    > The DataGrid should automatically provide unique names for the server
    > controls inside. See my article for some tips and details:
    >
    > In Search of ASP.NET Controls
    > http://odetocode.com/Articles/116.aspx
    >
    > --
    > Scott
    > http://www.OdeToCode.com/blogs/scott/
    >
    > On Thu, 30 Sep 2004 14:25:08 -0400, "Eric Caron"
    > <> wrote:
    >
    > >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?
    > >

    >
    Eric Caron, Sep 30, 2004
    #3
  4. Eric Caron

    Scott Allen Guest

    On Thu, 30 Sep 2004 15:00:36 -0400, "Eric Caron"
    <> wrote:

    HI Eric:

    >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,

    --
    Scott
    http://www.OdeToCode.com/

    >"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    >news:...
    >> Hi Eric:
    >>
    >> >"I tried to give the same name to the radio button
    >> >control."

    >>
    >> Can you give an show us your template columns?
    >>
    >> The DataGrid should automatically provide unique names for the server
    >> controls inside. See my article for some tips and details:
    >>
    >> In Search of ASP.NET Controls
    >> http://odetocode.com/Articles/116.aspx
    >>
    >> --
    >> Scott
    >> http://www.OdeToCode.com/blogs/scott/
    >>
    >> On Thu, 30 Sep 2004 14:25:08 -0400, "Eric Caron"
    >> <> wrote:
    >>
    >> >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?
    >> >

    >>

    >
    Scott Allen, Sep 30, 2004
    #4
  5. Eric Caron

    Eric Caron Guest

    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!

    "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    news:...
    > On Thu, 30 Sep 2004 15:00:36 -0400, "Eric Caron"
    > <> wrote:
    >
    > HI Eric:
    >
    > >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,
    >
    > --
    > Scott
    > http://www.OdeToCode.com/
    >
    > >"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    > >news:...
    > >> Hi Eric:
    > >>
    > >> >"I tried to give the same name to the radio button
    > >> >control."
    > >>
    > >> Can you give an show us your template columns?
    > >>
    > >> The DataGrid should automatically provide unique names for the server
    > >> controls inside. See my article for some tips and details:
    > >>
    > >> In Search of ASP.NET Controls
    > >> http://odetocode.com/Articles/116.aspx
    > >>
    > >> --
    > >> Scott
    > >> http://www.OdeToCode.com/blogs/scott/
    > >>
    > >> On Thu, 30 Sep 2004 14:25:08 -0400, "Eric Caron"
    > >> <> wrote:
    > >>
    > >> >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?
    > >> >
    > >>

    > >

    >
    Eric Caron, Sep 30, 2004
    #5
  6. Eric Caron

    Scott Allen Guest

    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

    On Thu, 30 Sep 2004 17:28:42 -0400, "Eric Caron"
    <> wrote:

    >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!
    >
    >"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    >news:...
    >> On Thu, 30 Sep 2004 15:00:36 -0400, "Eric Caron"
    >> <> wrote:
    >>
    >> HI Eric:
    >>
    >> >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,
    >>
    >> --
    >> Scott
    >> http://www.OdeToCode.com/
    >>
    >> >"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    >> >news:...
    >> >> Hi Eric:
    >> >>
    >> >> >"I tried to give the same name to the radio button
    >> >> >control."
    >> >>
    >> >> Can you give an show us your template columns?
    >> >>
    >> >> The DataGrid should automatically provide unique names for the server
    >> >> controls inside. See my article for some tips and details:
    >> >>
    >> >> In Search of ASP.NET Controls
    >> >> http://odetocode.com/Articles/116.aspx
    >> >>
    >> >> --
    >> >> Scott
    >> >> http://www.OdeToCode.com/blogs/scott/
    >> >>
    >> >> On Thu, 30 Sep 2004 14:25:08 -0400, "Eric Caron"
    >> >> <> wrote:
    >> >>
    >> >> >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?
    >> >> >
    >> >>
    >> >

    >>

    >


    --
    Scott
    http://www.OdeToCode.com/
    Scott Allen, Oct 1, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hermit Dave
    Replies:
    0
    Views:
    420
    Hermit Dave
    Jan 22, 2004
  2. JKop
    Replies:
    3
    Views:
    453
  3. News Sympatico
    Replies:
    0
    Views:
    301
    News Sympatico
    May 21, 2005
  4. tab 2 into tab 4 ?

    , Jun 19, 2005, in forum: Python
    Replies:
    2
    Views:
    313
  5. recover
    Replies:
    2
    Views:
    788
    recover
    Jul 25, 2006
Loading...

Share This Page