1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Hidden boundfield with RowDataBound not working?

Discussion in 'C#' started by binici, Dec 4, 2006.

  1. #1
    Tyring to retrieve value from a hidden boundfield, but it is not returning the value within the logic, please see the code and then my short explaination at the bottom.

    Here is the gridview with the columns bound to my sqldatasource:
    <asp:GridView ID="RecipHistoryGridView" runat="server" DataSourceID="sqlRecipHistory" AutoGenerateColumns="False" DataKeyNames="recip_id,member_id" DataMember="DefaultView" AllowPaging="True" CssClass="TextSmall" Width="555px" Visible="False" AllowSorting="True" PageSize="5" OnRowDataBound="RecipHistoryGridView_RowDataBound">
    <Columns>
    <asp:HyperLinkField DataTextField="recip_id" HeaderText="View" NavigateUrl="/_MembersOnly/RecipListing/RecipListingForm.aspx"
    SortExpression="recip_id" />
    <asp:BoundField DataField="recip_to" HeaderText="To" SortExpression="recip_to" />
    <asp:BoundField DataField="recip_status" HeaderText="Status" SortExpression="recip_status" />
    <asp:BoundField DataField="agent_name" HeaderText="Agent" SortExpression="agent_name" />
    <asp:BoundField DataField="office_name" HeaderText="Office" SortExpression="office_name" />
    <asp:BoundField DataField="recip_address" HeaderText="Address" SortExpression="recip_address" />
    <asp:BoundField DataField="mls_id" HeaderText="MLS #" SortExpression="mls_id" />
    <asp:BoundField DataField="recip_date" DataFormatString="{0:d}" HeaderText="Entered"
    HtmlEncode="False" SortExpression="recip_date" />
    <asp:BoundField DataField="recip_type" HeaderText="RecipType" SortExpression="recip_type"
    Visible="False" />
    </Columns>
    <HeaderStyle BackColor="#5C6F8D" HorizontalAlign="Center" />
    <AlternatingRowStyle BackColor="#8B9FC4" />
    <PagerSettings Mode="NextPreviousFirstLast" />
    <PagerStyle HorizontalAlign="Center" />
    </asp:GridView>

    The code behind logic to change the text of the first column if the hidden field value is something:

    Protected Sub RecipHistoryGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles RecipHistoryGridView.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then

    ' Change the first column (recip_id) to a status string.
    If e.Row.Cells(8).Text = "1" Then
    e.Row.Cells(0).Text = "Listing In"
    ElseIf e.Row.Cells(8).Text = "0" Then
    e.Row.Cells(0).Text = "Listing Out"
    End If
    End If

    End Sub

    The problem is, when the Recip Type column in hidden the logic doesn't work? But when i set the column to visible the logic fires off correctly.

    Any ideas?

    Thank you!
     
    binici, Dec 4, 2006 IP
  2. binici

    binici Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Figured this out!

    Here is the soultion for VB:

    Seems like a DataRowView is used to the displayed content with different attributes! Here is the VB Code:

    Protected Sub RecipHistoryGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles RecipHistoryGridView.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then

    ' Change the first column (recip_id) to a status string.

    Dim d As DataRowView = e.Row.DataItem()
    If d("recip_type").ToString = "1" Then
    e.Row.Cells(0).Text = "Listing In"
    ElseIf d("recip_type").ToString = "0" Then
    e.Row.Cells(0).Text = "Listing Out"
    End If

    End If

    End Sub

    Thanks again!
     
    binici, Dec 5, 2006 IP