DataGrid - if/else in edititemtemplate?

J

JW

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
 
J

JW

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
 

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

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top