Reposting ItemTemplate problem (sorry)

Results 1 to 2 of 2

Thread: Reposting ItemTemplate problem (sorry)

  1. #1
    Join Date
    Dec 1969

    Default Reposting ItemTemplate problem (sorry)

    Sorry to repost this. This is my first time on here and I screwed up my first post by replying to myself and I was afraid I wouldn&#039;t get a response. Again, I&#039;m really sorry.<BR><BR>I have created a dataGrid on a web form using VB.Net. Here is what I am trying to do... <BR><BR>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&#039;t get it to show up in a textbox. Any suggestions?? Thanks in advance. <BR><BR> <BR><BR>this is from my html page..... <BR><BR>
    <BR><BR>&#060;asp:TemplateColumn SortExpression="Name" HeaderText="Name"&#062; &#060;ItemTemplate&#062;<BR><BR>&#060;%# RenderNameField(Databinder.Eval(Container, "DataItem.vacancy_flag")<BR><BR>,Databinder.Eval(Container, "DataItem.Name")) %&#062;<BR><BR>&#060;/ItemTemplate&#062; <BR><BR>&#060;/asp:TemplateColumn&#062; <BR><BR>
    <BR><BR> <BR><BR>this is from my codebehind page...... <BR><BR>
    <BR><BR>Function RenderNameField(ByVal sVacantFlag As String, ByVal sText As String) As String <BR><BR>If Not Convert.ToBoolean(Byte.Parse(sVacantFlag)) Then <BR><BR>Return "&#060;asp:Label runat=server Text=""" & sText & """&#062;" & sText & "&#060;/asp:Label&#062;" <BR><BR>Else <BR><BR>Return "&#060;asp:TextBox runat=server ID=txtName width=10px&#062;Vacant Slot&#060;/asp:TextBox&#062;" <BR><BR>End If <BR><BR>End Function <BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Different Approach

    I think I would simplify this a little - <BR><BR>First of all I would alter your stored procedure to test for a vacant slot - so it would either return the Name or the text "Vacant Slot".<BR><BR>I would then create an OnItemDataBound procedure which checks if "Vacant Slot" is returned. If false I would make the textbox read only.<BR><BR>Off the top of my head something like this:<BR><BR>Sub YourDataGrid_ItemDataBound(s as object, e as DataGridItemEventArgs)<BR>Select Case e.Item.ItemType<BR>Case ListItemType.Item, ListItemType.AlternatingItem<BR><BR>TheTextBox = ctype(e.item.cells(0).Controls(0),Textbox)<BR>If TheTextBox.Text &#060;&#062; "Vacant Slot" Then <BR>TextBox.ReadOnly = True<BR>End If<BR>End Select<BR>End Sub<BR><BR>I haven&#039;t tested the above so it will probably need some alterations - Once you&#039;ve got this working you can then look at replacing the textbox with a label!!<BR><BR>Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts