Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp.net vb.net need help with hiding the select button in gridview

Status
Not open for further replies.

leo57

Programmer
Oct 28, 2013
33
US
background. I want to be able to hide or gray out a Select button for people that are Not employees. For employees the button should work and select them.
I have a select button I added using GridView tasks, Edit columns, but did not know how to hide it or gray it or other wise.
whihc aal works fine except I can't figure out how to name the button to hide it in the GridView3_RowDataBound procedure.
So I added another select button. but I found the only way to detect that button push was in the gridview_rowCommand.

So I have this code to try and get the row index but when pressing the new button there is no e.commandargument (get error) can't convert to string
Code:
Private Sub GridView3_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView3.RowCommand
        [highlight #FCE94F]Dim index As Integer = Convert.ToInt32(e.CommandArgument)[/highlight] ' Error: Input string was not in a correct format.
        Dim row As GridViewRow = GridView3.Rows(index)
        Session("EnterpriseID") = HttpUtility.HtmlDecode(GridView3.Rows(index).Cells(2).Text)
...
' this code hides the second select button , which is named btnSelect, but how can I name the original Select button in the HTML markup?
Private Sub GridView3_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then

            If (DataBinder.Eval(e.Row.DataItem, "LegacyPersonType") <> "Employee") Then
                e.Row.ForeColor = Drawing.Color.Black
                e.Row.BackColor = Drawing.Color.Yellow ' This will make row back color yellow 
                e.Row.FindControl("btnSelect").Visible = False
            Else
                e.Row.ForeColor = Drawing.Color.Black
                e.Row.BackColor = Drawing.Color.White   ' the normal employees make white
            End If

        End If
If I use the original Select button there is a e.commandargument but I need to name the button for this code to work in the HTML markup?
Or maybe in the Gridview tasks?
So any ides how to gray it out or hide it.
hope all this makes sense.
TIA

 
addendum to above
I can name give a TemplateField an ID but not a CommandField ?

<asp:CommandField ButtonType="Button" ShowCancelButton="False"
ShowSelectButton="True" ID="BtnSelect2"/> <!-- Error: ID is not a valid field for CommandField -->
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="BtnSelect" runat="server" Text="Select" /> <!-- but this work fine, go figure -->
</ItemTemplate>
</asp:TemplateField>

 
I figured it out.
I made the default Select button in the grid a Template field. This then gave it a name which could be found using the "findControl" method, And this is how the GridView3_RowCommand makes it invisible.
and since it was a default Select button it had the code to make it selectable.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top