4 Replies - 2379 Views - Last Post: 02 July 2010 - 08:59 AM Rate Topic: -----

#1 patientD1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-August 09

Highlighting a row dynamically based on a value

Posted 01 July 2010 - 09:30 PM

I have a label which gets a case number when the page loads.

I have a grid view which shows all the concurrent case numbers. I want to highlight the row in the grid view which has the same case number as in the label. I tried doing it using several methods, but it didn't work, although it compiles fine. Please help me to accomplish this. Pls suggest corrections.
Option 1: using OnRowDataBound as shown in the code below

 <table id = "pt_info_table>
<tr>
<td>CSI Case No :</td>
<td><asp:Label ID="pt_caseNo" runat="server" /></td>
...
</tr>

</table>


<asp:GridView ID="gvConcurrentCases" runat="server"
            EmptyDataText="No Concurrent cases Found"  
        AutoGenerateColumns="False" EnableViewState = "true"  HeaderStyle-Height = "20" RowStyle-Height = "20"
        OnRowDataBound = "gvConcurrentCases_OnDataBound">
        <Columns>
         <asp:TemplateField >
                <ItemTemplate >
                        <asp:CheckBox ID="CheckBoxMerge" runat="server" Enabled="true" />
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" />
                <HeaderTemplate >
                    <asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
                </HeaderTemplate>
            </asp:TemplateField>
        <asp:TemplateField HeaderText="Case No.">
                <ItemTemplate>
                <asp:Label ID="LblCaseNo" runat="server" Text='<%# Eval("CaseNo") %>' visible="false"></asp:Label>  
              <a class="link_Concurrent" href='details.aspx?caseno=<%# Eval("CaseNo") %>&ai=<%# Request.QueryString["ai"] %>&pi=<%# Request.QueryString["pi"] %>&ci=<%# Request.QueryString["ci"] %>'>
                <%# Eval("CaseNo") %>
                </a>
                </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Case Type" DataField="CaseTypeName" />
        <asp:TemplateField HeaderText="Accession Date" >
            <ItemTemplate>
                <%# completedDateAndStep(DataBinder.Eval(Container.DataItem, "CreatedDate").ToString(), Eval("StepName").ToString())%>
            </ItemTemplate>
        </asp:TemplateField><asp:TemplateField HeaderText="Completed Date" >
            <ItemTemplate>
                <%# completedDateAndStep(DataBinder.Eval(Container.DataItem, "CompletedDate").ToString(), Eval("StepName").ToString())%>
                <asp:Label ID="CompletedStatus" runat="server" Text='<%# Eval("StepName") %>' visible="false"></asp:Label>  
            </ItemTemplate>
        </asp:TemplateField>        
        <asp:TemplateField HeaderText="Note"  >
            <ItemTemplate>
            
            </ItemTemplate>
        </asp:TemplateField>


        </Columns>
        </asp:GridView>       

    <asp:Label ID="Label1" runat="server" ></asp:Label><br />
    <asp:Button ID="MergeReports" runat="server" Text="Batch Save Reports" onclick="MergeReportFiles" />



 protected void Page_PreRender(object sender, EventArgs e)
    {
        getConcurrentCases();
        RemoveCheckBoxes();
        PutCheckMarks();
        
    }

    protected void gvConcurrentCases_OnDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "CaseNo")) == pt_caseNo.Text.ToString())
            {
                e.Row.BackColor = System.Drawing.Color.Blue;
            }
        }
    }



    protected void MergeReportFiles(object sender, EventArgs e)
    {
        Label1.Text = "          ";
        int NumOfReportsSelected = GetCaseNumsForMerge();
        //if (NumOfReportsSelected < gvConcurrentCases.Rows.Count)
        //    Page.RegisterStartupScript("if (Confirm", "<script language=Javascript>confirm('Not all cases are signed out. Are you sure to continue'));</script>");

        {
            string[] ReportFileNames = GetReportFileNames();
            foreach (string item in ReportFileNames)
            {
                string curFile = item;
                if (!File.Exists(curFile))
                    Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "ALERT", "alert('" + curFile.Substring(36) + ": Report Not Found');", true);
            }
            saveMergedFile(ReportFileNames);
        }

    }


Option2: going through each row in the grid and checking the value match
 <table id = "pt_info_table>
<tr>
<td>CSI Case No :</td>
<td><asp:Label ID="pt_caseNo" runat="server" /></td>
...
</tr>

</table>


<asp:GridView ID="gvConcurrentCases" runat="server"
            EmptyDataText="No Concurrent cases Found" 
        AutoGenerateColumns="False" EnableViewState = "true" HeaderStyle-Height = "20" RowStyle-Height = "20">
        <Columns>
         <asp:TemplateField ItemStyle-HorizontalAlign ="Center" ItemStyle-VerticalAlign = "Middle" >
                <ItemTemplate  >
                        <asp:CheckBox ID="CheckBoxMerge" runat="server" Enabled="true"  />
                </ItemTemplate>               
                <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" />
                <HeaderTemplate >
                    <asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
                </HeaderTemplate>
            </asp:TemplateField>
        <asp:TemplateField HeaderText="Case No.">
                <ItemTemplate >
                <asp:Label ID="LblCaseNo" runat="server" Text='<%# Eval("CaseNo") %>' visible="false"></asp:Label> 
              <a href='details.aspx?caseno=<%# Eval("CaseNo") %>&ai=<%# Request.QueryString["ai"] %>&pi=<%# Request.QueryString["pi"] %>&ci=<%# Request.QueryString["ci"] %>'>
                <%# Eval("CaseNo") %>
                </a>
                </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Case Type" DataField="CaseTypeName"/>
        <asp:TemplateField HeaderText="Accession Date" ItemStyle-Height = "20">
            <ItemTemplate>
                <%# completedDateAndStep(DataBinder.Eval(Container.DataItem, "CreatedDate").ToString(), Eval("StepName").ToString())%>
            </ItemTemplate>
        </asp:TemplateField><asp:TemplateField HeaderText="Completed Date">
            <ItemTemplate>
                <%# completedDateAndStep(DataBinder.Eval(Container.DataItem, "CompletedDate").ToString(), Eval("StepName").ToString())%>
                <asp:Label ID="CompletedStatus" runat="server" Text='<%# Eval("StepName") %>' visible="false"></asp:Label> 
            </ItemTemplate>
        </asp:TemplateField>       
        <asp:TemplateField HeaderText="Note">
            <ItemTemplate>
           
            </ItemTemplate>
        </asp:TemplateField>
       
        </Columns>
 </asp:GridView>      

 <asp:Label ID="Label1" runat="server" ></asp:Label><br />
 <asp:Button ID="MergeReports" runat="server" Text="Batch Save Reports" onclick="MergeReportFiles" />

 protected void doSomething()
    {
            int NumOfRows = gvConcurrentCases.Rows.Count;
            foreach (GridViewRow gvr in gvConcurrentCases.Rows)
            {
                Label CaseNo1 = (Label)gvr.FindControl("LblCaseNo");
                if (CaseNo1.Text.ToString() == pt_caseNo.Text.ToString())
                {
                    gvr.ForeColor = Color.Blue;
                }
                Label CompletedStatus = (Label)gvr.FindControl("CompletedStatus");
                if (CompletedStatus.Text.ToString().Trim() != "Complete")
                {
                    NumOfRows = NumOfRows - 1;
                    CheckBox chk = (CheckBox)gvr.FindControl("CheckBoxMerge") as CheckBox;
                    if (chk != null)
                    {
                        chk.Visible = false;
                    }
                }
            }
            if (NumOfRows == 0) MergeReports.Enabled = false;
       
    }


Is This A Good Question/Topic? 0
  • +

Replies To: Highlighting a row dynamically based on a value

#2 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Highlighting a row dynamically based on a value

Posted 02 July 2010 - 04:49 AM

There should be a "RowStyle-CssClass" attribute for the GridView. To set that, you would need to do something like this...

<asp:GridView .... 
RowStyle-CssClass='<% Eval("CaseNo") == pt_caseNo.Text ? "css_SameAsCaseNo" : "css_DifferntFromCase" %>' ...>

// the rest of your markup

</asp:GridView>



this hasn't been tested by this is one way to do it. You are basically doing an inline-if statement to determine the CSS class that will be used for the row.

This, of course, would mean that you need to use CSS.

This post has been edited by eclipsed4utoo: 02 July 2010 - 04:52 AM

Was This Post Helpful? 0
  • +
  • -

#3 patientD1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-August 09

Re: Highlighting a row dynamically based on a value

Posted 02 July 2010 - 07:13 AM

View Posteclipsed4utoo, on 02 July 2010 - 03:49 AM, said:

There should be a "RowStyle-CssClass" attribute for the GridView. To set that, you would need to do something like this...

<asp:GridView .... 
RowStyle-CssClass='<% Eval("CaseNo") == pt_caseNo.Text ? "css_SameAsCaseNo" : "css_DifferntFromCase" %>' ...>

// the rest of your markup

</asp:GridView>



this hasn't been tested by this is one way to do it. You are basically doing an inline-if statement to determine the CSS class that will be used for the row.

This, of course, would mean that you need to use CSS.


I tried this one also. It did not work.
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Highlighting a row dynamically based on a value

Posted 02 July 2010 - 07:46 AM

how are you binding to the grid? DataTable?
Was This Post Helpful? 0
  • +
  • -

#5 patientD1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-August 09

Re: Highlighting a row dynamically based on a value

Posted 02 July 2010 - 08:59 AM

Reply to "how are you binding to the grid? DataTable? "

protected void Page_PreRender(object sender, EventArgs e)
    {
        getConcurrentCases();
        RemoveCheckBoxes();
        PutCheckMarks();        
    }

 protected void getConcurrentCases()
    {
        gvConcurrentCases.DataSource = csiDelegate.DataTableProcedure("Case_Concurrent_cases", _accesionID, _caseno);
        gvConcurrentCases.DataBind();
    }


protected void PutCheckMarks()
    {
        string[] CaseNos = Val.Split(' ');
        foreach (GridViewRow gvr in gvConcurrentCases.Rows)
        {
            Label LblCaseNo = (Label)gvr.FindControl("LblCaseNo");
            if (CaseNos.Contains(LblCaseNo.Text.ToString()))
            {
                CheckBox chk = (CheckBox)gvr.FindControl("CheckBoxMerge") as CheckBox;

                if (chk != null && chk.Visible == true)
                {
                    chk.Checked = true;
                }
            }
        }
    }

    protected void RemoveCheckBoxes()
    {
        int StatusComplete = gvConcurrentCases.Rows.Count;
        foreach (GridViewRow gvr in gvConcurrentCases.Rows)
        {
            Label CompletedStatus = (Label)gvr.FindControl("CompletedStatus");
            if (CompletedStatus.Text.ToString().Trim() != "Complete")
            {
                StatusComplete = StatusComplete - 1;
                CheckBox chk = (CheckBox)gvr.FindControl("CheckBoxMerge") as CheckBox;
                if (chk != null)
                {
                    chk.Visible = false;
                }
            }
        }
        if (StatusComplete == 0) MergeReports.Enabled = false;
    }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1