DataGrid - if/else in edititemtemplate?

Discussion in 'ASP .Net Datagrid Control' started by JW, May 16, 2004.

  1. JW

    JW Guest

    Greetings -

    I am working with a DataGrid, and am trying to set up a template column for
    a password field which is stored in a database. Basically, when the
    "EditCommand" is executed, for the EditItemTemplate, I would like to display
    a HyperLink if a password exists for this particular table row, or a TextBox
    if one does not. ( the hyperlink will be a "reset" link, whereas the
    textbox will allow the user to enter a password if one does not exist. Here
    is my code so far, which I'm sure is far from correct ( pwdLength is an
    int ):

    <asp:templatecolumn headertext="Password">
    <edititemtemplate>
    <%# if( DataBinder.Eval( Container.DataItem, "pwdLength" ) == 0 )
    {
    <asp:textbox id="password_Textbox" runat="server"
    text="something" visible="True"></asp:textbox>
    } else {
    <asp:hyperlink id="password_Link" runat="server" text="reset"
    navigateurl="tobedecided" />
    } %>
    </edititemtemplate>
    </asp:templatecolumn>

    Currently, the browser compiler is complaining "Invalid expression term
    'if'"...... am I going about this completely wrong? I do have a
    code-behind file where most of my C# code is, however for some reason I
    thought this if/else should go in the .aspx file.

    Thanks in advance,
    Justin
     
    JW, May 16, 2004
    #1
    1. Advertising

  2. JW

    JW Guest

    Ok, I ditched my first idea, and was able to get the concept working by just
    adding both controls ( a linkbutton - I initially thought a hyperlink would
    work, but I decided on linkbutton instead - and a textbox ) and just setting
    the visibility to true/false depending on whether or not a password was
    present in my "onitemdatabound" method. Here is a sample of what I did:

    <asp:templatecolumn headertext="Password">
    <edititemtemplate>
    <asp:textbox id="password_Textbox" runat="server" text=""
    width="100" maxlength="50"></asp:textbox>
    <asp:linkbutton id="password_Reset" runat="server" text="reset"
    commandname="ResetPassword"></asp:linkbutton>
    </edititemtemplate>
    </asp:templatecolumn>

    Justin



    "JW" <> wrote in message
    news:...
    > Greetings -
    >
    > I am working with a DataGrid, and am trying to set up a template column

    for
    > a password field which is stored in a database. Basically, when the
    > "EditCommand" is executed, for the EditItemTemplate, I would like to

    display
    > a HyperLink if a password exists for this particular table row, or a

    TextBox
    > if one does not. ( the hyperlink will be a "reset" link, whereas the
    > textbox will allow the user to enter a password if one does not exist.

    Here
    > is my code so far, which I'm sure is far from correct ( pwdLength is an
    > int ):
    >
    > <asp:templatecolumn headertext="Password">
    > <edititemtemplate>
    > <%# if( DataBinder.Eval( Container.DataItem, "pwdLength" ) ==

    0 )
    > {
    > <asp:textbox id="password_Textbox" runat="server"
    > text="something" visible="True"></asp:textbox>
    > } else {
    > <asp:hyperlink id="password_Link" runat="server" text="reset"
    > navigateurl="tobedecided" />
    > } %>
    > </edititemtemplate>
    > </asp:templatecolumn>
    >
    > Currently, the browser compiler is complaining "Invalid expression term
    > 'if'"...... am I going about this completely wrong? I do have a
    > code-behind file where most of my C# code is, however for some reason I
    > thought this if/else should go in the .aspx file.
    >
    > Thanks in advance,
    > Justin
    >
    >
     
    JW, May 16, 2004
    #2
    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. Trevor Hartman

    datagrid edititemtemplate for dates

    Trevor Hartman, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    371
    Trevor Hartman
    Jul 16, 2003
  2. Replies:
    25
    Views:
    687
    MonkeeSage
    Oct 1, 2006
  3. kj
    Replies:
    15
    Views:
    580
    Lawrence D'Oliveiro
    May 23, 2009
  4. A
    Replies:
    8
    Views:
    819
    James Kanze
    Aug 28, 2010
  5. Gergely Kontra
    Replies:
    16
    Views:
    238
    Devin Mullins
    Sep 20, 2005
Loading...

Share This Page