Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-16
2
Medium Priority
?
538 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:migusto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
AngryBinary earned 2000 total points
ID: 34149888
Add the ID column (serviceid, I think?) to the DataKeyNames for the GridView:

<asp:GridView DataKeyNames="serviceid" runat="server" etc...

Your GridView will store the value in a collection accessible in your code, as long as you know the row index that you want the ID for:

GridView1.DataKeys[rowIndex].Value
0
 

Author Closing Comment

by:migusto
ID: 34150078
that works, thank you for the quick response. ()'s instead of [] for the datakeys parameter though.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question