problem with GridView1_RowDataBound

Last post 05-10-2008 12:54 AM by sunilbotadara. 5 replies.

Sort Posts:

  • problem with GridView1_RowDataBound

    05-09-2008, 2:45 AM
    • Loading...
    • tartuffe2
    • Joined on 06-28-2006, 10:15 AM
    • Posts 292

    Hi,

    i want to make the forecolor of values into a gridview red but only when
    they equals 'n'.

     <asp:GridView ID="GridView1" runat="server"
            DataKeyNames="hour,place" DataSourceID="SqlDataSource1" >
           <Columns>
                <asp:CommandField ShowEditButton="True"/>
                <asp:BoundField DataField="place" HeaderText="place"
    ReadOnly="True" />
                <asp:BoundField DataField="hour" HeaderText="hour"
    ReadOnly="True" />

                <asp:TemplateField HeaderText="theday">
                        <EditItemTemplate>
                   <asp:DropDownList ID="DropDownList1" SelectedValue='<%#
    Bind("theday") %>' runat="server">
                   <asp:ListItem Text="y" Value="y"></asp:ListItem>
                    <asp:ListItem Text="n" Value="n"></asp:ListItem>
                   </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                 <asp:Label ID="Label2" runat="server" Text='<%# Bind("theday")
    %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

          </Columns>
    </asp:GridView>


    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    GridView1.RowDataBound

            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim m As String
                m = e.Row.Cells(3).Text
               If m = "n" Then
                    e.Row.Cells(3).ForeColor = Drawing.Color.Red
                End If
           End If
        End Sub

    The values are correctly rendered, i can update etc ... but the forecolor remains black. Is this due to the template?

    I tested with this code: response.write(e.Row.Cells(3).Text) which gives nothing ...
    Thanks for help

    T.

  • Re: problem with GridView1_RowDataBound

    05-09-2008, 5:36 AM
    Answer
    • Loading...
    • Mahadeomatre
    • Joined on 04-23-2007, 11:00 AM
    • Pune, India
    • Posts 190

    e.Row.cell(3).text is null, because cell(3) is ur templete column. so u r requried to find that control in that cell, and then take the value of that ctrl and compaire. .

    for lable

    Lable a= (Lable) e.row.cell[3].findControl("label2");

    string a=a.text;

    Thanks,
    Mahadeo

    -----------------------------------------------
    Best is Not the END point, but a starting point for Innovation
    ------------------------------------------------
    Remember to mark posts as the "Answer" to help future users.
  • Re: problem with GridView1_RowDataBound

    05-09-2008, 7:10 AM

    Try this in Grid's RowDatabound

    ((Label)e.Row.FindControl("lblName")).ForeColor = System.Drawing.ColorTranslator.FromHtml("#003c73");

    If it is useful to u then plz Marked this as ANSWERED.

    If my answer useful to you,plz Marked as ANSWERED

    Sunil Amrutbhai Botadara,
    Web Developer,
    Email:sunil_botadara@yahoo.co.in
  • Re: problem with GridView1_RowDataBound

    05-09-2008, 8:27 AM
    • Loading...
    • chandan.max
    • Joined on 03-28-2008, 6:37 AM
    • India
    • Posts 155

    Hi
    use this: 

     

    ((Label)e.Row.FindControl("lblName")).ForeColor = System.Drawing.Color.Red;
     
    "Mark as Answer" on the post that helped you.

    Chandan,
    Imfinity India Pte Ltd.
  • Re: problem with GridView1_RowDataBound

    05-09-2008, 12:18 PM
    • Loading...
    • tartuffe2
    • Joined on 06-28-2006, 10:15 AM
    • Posts 292

    Thanks to all, it works now.

    But why do Sunil and Chandan just repeat what you wrote? Are you payed by answers?

  • Re: problem with GridView1_RowDataBound

    05-10-2008, 12:54 AM

    First you read with care then write anything,i was not repeate i write different from you write

    you write e.Row.Cells(3).ForeColor = Drawing.Color.Red

    And i wrote that is ((Label)e.Row.FindControl("lblName")).ForeColor = System.Drawing.ColorTranslator.FromHtml("#003c73");

    i think it will useful to you but i think like you no need to help.

    understand....

    If my answer useful to you,plz Marked as ANSWERED

    Sunil Amrutbhai Botadara,
    Web Developer,
    Email:sunil_botadara@yahoo.co.in
Page 1 of 1 (6 items)