ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1737
Number of posts: 3308

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
dataGrid ItemTemplate question Posted by begels02 on 18 Oct 2004 at 5:36 AM
I have created a dataGrid on a web form using VB.Net. Here is what I am trying to do...
The first column in the dataGrid I have created an ItemTemplate. What I would like for it to do is either display a textbox or a label. Basically, if there is a name in the recordset I pulled from my stored procedure, print it out. If not, I want a textbox to display with the text Vacant Slot. I am getting it to either print the name or the words "Vacant Slot" but I can't get it to show up in a textbox. Any suggestions?? Thanks in advance.

this is from my html page.....
 
<asp:TemplateColumn SortExpression="Name" HeaderText="Name"> 
<ItemTemplate> <%# RenderNameField(Databinder.Eval (Container, "DataItem.vacancy_flag"),Databinder.Eval
(Container, "DataItem.Name")) %> 
</ItemTemplate> 
</asp:TemplateColumn> 


this is from my codebehind page......
 
Function RenderNameField(ByVal sVacantFlag As String, ByVal sText As 
String) As String 
If Not Convert.ToBoolean(Byte.Parse(sVacantFlag)) Then 
Return "<asp:Label runat=server Text=""" & sText & """>" & sText & "</asp:Label>" 
Else 
Return "<asp:TextBox runat=server ID=txtName width=10px>Vacant Slot</asp:TextBox>" 
End If 
End Function 

Report
Re: dataGrid ItemTemplate question Posted by iwilld0it on 18 Oct 2004 at 6:06 AM
: I have created a dataGrid on a web form using VB.Net. Here is what I am trying to do...
: The first column in the dataGrid I have created an ItemTemplate. What I would like for it to do is either display a textbox or a label. Basically, if there is a name in the recordset I pulled from my stored procedure, print it out. If not, I want a textbox to display with the text Vacant Slot. I am getting it to either print the name or the words "Vacant Slot" but I can't get it to show up in a textbox. Any suggestions?? Thanks in advance.
:
: this is from my html page.....
:
 
: <asp:TemplateColumn SortExpression="Name" HeaderText="Name"> 
: <ItemTemplate> <%# RenderNameField(Databinder.Eval (Container, "DataItem.vacancy_flag"),Databinder.Eval
: (Container, "DataItem.Name")) %> 
: </ItemTemplate> 
: </asp:TemplateColumn> 
: 

:
: this is from my codebehind page......
:
 
: Function RenderNameField(ByVal sVacantFlag As String, ByVal sText As 
: String) As String 
: If Not Convert.ToBoolean(Byte.Parse(sVacantFlag)) Then 
: Return "<asp:Label runat=server Text=""" & sText & """>" & sText & "</asp:Label>" 
: Else 
: Return "<asp:TextBox runat=server ID=txtName width=10px>Vacant Slot</asp:TextBox>" 
: End If 
: End Function 
: 

:

It wont work like that. You are trying to dynamically build the string for the control, however, by the time that sting prints, the control rendering engine has long executed. It's kind of like the chicken before the egg scenario.

Your best bet is to place the two controls in the Item Template and set the visibility of either conntrol to false, depending on your scenario ...

myTextBox.Visible = "False"

Report
Re: dataGrid ItemTemplate question Posted by singhrohit82 on 22 Nov 2004 at 10:32 PM
Hello,
Infact you can place a textbox and a label control in the ItemTemplate at design time and in the ItemDataBound event of the grid you can hide and show it as required.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.