Link to home
Start Free TrialLog in
Avatar of migusto
migustoFlag for Canada

asked on

Need help getting the value of a hidden BoundField from code-behind

I have a Gridview with a dropdown in each row that will automatically postback and update the current row based on the serviceid. However I need to hide the first column as the end users are not interested in the ID. If I make the BoundField invisble the code-behind can't see it either. Does anyone have any ideas for a way to either hide the serviceid column or another approach?

I've included the Gridview and appropriate code below to give you an idea of what I'm trying to do. Thanks!

      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSourceServices" BackColor="White" BorderColor="White" 
            BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" 
            GridLines="None" Width="800" DataKeyNames="serviceid" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            <Columns>
                <asp:BoundField DataField="serviceid" InsertVisible="False" 
                    ReadOnly="True" SortExpression="serviceid" Visible="True" />
                <asp:BoundField DataField="servicename" HeaderText="Service" 
                    SortExpression="servicename" />
                <asp:BoundField DataField="servicetype" HeaderText="Service Type" 
                    SortExpression="servicetype" Visible="False" />
                <asp:TemplateField HeaderText="Current">
                    <ItemTemplate>
                      <asp:DropDownList ID="ddlUpdateStatus" EnableViewState="true" SelectedValue='<%# Bind("status") %>' 
                            runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlUpdateStatus_SelectedIndexChanged">
                           <asp:ListItem value="0">0</asp:ListItem>
                           <asp:ListItem value="1">1</asp:ListItem>
                           <asp:ListItem value="2">2</asp:ListItem>
                           <asp:ListItem value="3">3</asp:ListItem>
                      </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>




    Protected Sub ddlUpdateStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim ddlCurrentDropDownList As DropDownList = DirectCast(sender, DropDownList)
        Dim grdrDropDownRow As GridViewRow = DirectCast(ddlCurrentDropDownList.Parent.Parent, GridViewRow)
        Dim selectedStatus As Integer = ddlCurrentDropDownList.SelectedItem.Value
        Dim selectedLab As String = ddlLabList.SelectedValue
       	'get the value in the first column of the current row of the GridView for SQL update
	Dim selectedService As Integer = grdrDropDownRow.Cells(0).Text
	Me.lblService.Text = selectedSservice
	SqlDataSourceServices.Update()
    End Sub

    Private Sub SqlDataSourceServices_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles 		SqlDataSourceServices.Updating
        e.Command.Parameters("@selectedService").Value = Me.lblService.Text
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AngryBinary
AngryBinary

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of migusto

ASKER

that works, thank you for the quick response. ()'s instead of [] for the datakeys parameter though.