Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

dataGrid ItemTemplate question

begels02begels02 Posts: 3Member
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.....
[code]

<%# RenderNameField(Databinder.Eval (Container, "DataItem.vacancy_flag"),Databinder.Eval
(Container, "DataItem.Name")) %>


[/code]

this is from my codebehind page......
[code]
Function RenderNameField(ByVal sVacantFlag As String, ByVal sText As
String) As String
If Not Convert.ToBoolean(Byte.Parse(sVacantFlag)) Then
Return "" & sText & ""
Else
Return "Vacant Slot"
End If
End Function
[/code]

Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    : 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.....
    : [code]
    :
    : <%# RenderNameField(Databinder.Eval (Container, "DataItem.vacancy_flag"),Databinder.Eval
    : (Container, "DataItem.Name")) %>
    :
    :
    : [/code]
    :
    : this is from my codebehind page......
    : [code]
    : Function RenderNameField(ByVal sVacantFlag As String, ByVal sText As
    : String) As String
    : If Not Convert.ToBoolean(Byte.Parse(sVacantFlag)) Then
    : Return "" & sText & ""
    : Else
    : Return "Vacant Slot"
    : End If
    : End Function
    : [/code]
    :

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

    [code]
    myTextBox.Visible = "False"
    [/code]
  • singhrohit82singhrohit82 Posts: 33Member
    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.


Sign In or Register to comment.