none
Higlight new record in asp.net

    Question

  • i use repeater in my project .. so when user add new document then i want to highlight new add documents same as gmail when we see new email in gmail account then email is in bold and then we able to see someone send email same as i want when new record added then how to highlight or identify in other ways? this is repeater code..

      <table class="CSSTableGenerator" border="0"  cellpadding="0" cellspacing="0" id="results">
                            <asp:Repeater ID="Repeater2" OnItemCommand="Repeater2_ItemCommand"   
                                runat="server" onitemdatabound="Repeater2_ItemDataBound">
                                <HeaderTemplate>
                                    <tr>
                                        
                                       <%-- <td>
                                           DocumentID
                                        </td>--%>
                                        <td>
                                           Document Name
                                        </td>
                                        <td>
                                            File Name
                                        </td>
                                        <td>
                                           Uploaded By
                                        </td>
                                        <td>
                                           Uploaded Date
                                        </td>
                                        <td>
                                            Email
                                        </td>
                                       
                                        <td>
                                            Department
                                        </td>
                                        <td>
                                            Status
                                        
                                        </td>
                                       
                                    </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr>
                                       
                                        
                                        <asp:HiddenField ID="DocId" runat="server" Value='<%#DataBinder.Eval(Container.DataItem, "DocID")%>' />
    <%--                                    <asp:Label Id="DocId" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DocID")%>'></asp:Label>
    --%>                                    
                                        <td>
                                        <asp:Label Id="DocName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DocumentName")%>'></asp:Label>
                                        </td>
                                        <td>
                                        <asp:Label Id="Uploadfile" runat="server"  Text='<%#DataBinder.Eval(Container.DataItem, "Uploadfile")%>'></asp:Label>
                                        </td>
                                         <td>
                                        <asp:Label Id="Label1" runat="server"  Text='<%#DataBinder.Eval(Container.DataItem, "UploadedBy")%>'></asp:Label>
                                        </td>
                                        <td>
                                        <asp:Label Id="UploadedDate" runat="server"  Text='<%#DataBinder.Eval(Container.DataItem, "UploadedDate")%>'></asp:Label>
                                        </td>
                                         <td>
                                        <asp:Label Id="YourEamil" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "UserEmail")%>'></asp:Label>
                                        </td>
                                        
                                        <td>
                                        <asp:Label Id="DepType" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Department")%>'></asp:Label>
                                        </td>
                                        
                                       
                                    <td>
                                
                                
                                 <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("ApproveID") %>' Visible = "false" />
                                  <asp:HiddenField ID="hfDepartmentId" runat="server" Value='<%# Eval("ApproveID") %>' />


                            <asp:DropDownList ID="DropDownList4" runat="server" EnableViewState="true" class="vpb_dropdown1" DataTextField="ApproveType" DataValueField="ApproveID" AutoPostBack="true" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged">
                                 <asp:ListItem Text="Pending" selected="selected" Value="3"></asp:ListItem>
                                 <asp:ListItem Text="Approve" Value="1"></asp:ListItem>
                                 <asp:ListItem Text="Reject" Value="2"></asp:ListItem>
                            </asp:DropDownList>
                            </td>
                            </tr>
                            </ItemTemplate>
                                </asp:Repeater>
                                </table>
                                      
                     
                     <asp:Label ID="Supvisor" runat="server" Font-Size="Medium" ForeColor="Red" ></asp:Label><br />
                     <asp:Label ID="Successz" runat="server" Font-Size="Medium" ForeColor="Green" ></asp:Label><br />

                <asp:Button ID="Button1" runat="server"   Text="Submit" onclick="Button1_Click" />

    someone suggegst me use flag for this ..but i dont know how i use it in sql and also in vs

    i add new column in table e.g

    column name datatype

    yes-no       bit


    and i create this sp

     SELECT dbo.DocumentInfo.DocID, dbo.DocumentInfo.DocName as DocumentName,
     dbo.DocumentInfo.Uploadfile,
     dbo.DocumentInfo.UploadedBy as UploadedBy,
     dbo.DocumentInfo.UploadedDate as UploadedDate,
     dbo.Userss.Email as UserEmail,
      dbo.Department.DepType as Department ,
      
     dbo.Designation.DesigType,
      dbo.ApproveType.ApproveType AS ApproveID
      FROM dbo.Department
      left JOIN dbo.DocumentInfo
      ON dbo.DocumentInfo.DepID=dbo.Department.DepID 
    
    
      left JOIN dbo.DocType
      ON  dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID
        inner JOIN dbo.Userss on Userss.UserName =dbo.DocumentInfo.UploadedBy 
         
     inner join dbo.Designation on dbo.Designation.DesigID=dbo.Userss.DesigID
       LEFT JOIN dbo.ApproveType
        ON dbo.ApproveType.approveid=dbo.Department.DepID
        where dbo.Department.DepID=@DepID  AND dbo.Designation.DesigType !='Supervisor'


    Thursday, January 23, 2014 2:09 PM

All replies

  • Change the <tr> to

    <tr

    style='<%if (datatype == 1) { %> background-color: yellow;  <% } else { %> background-color: white; <%} %>'>

    instead of datatype you need to use <%#databinder.eval(....

    • Edited by Don.O Thursday, January 23, 2014 2:36 PM
    Thursday, January 23, 2014 2:34 PM
  • whr i use this

     <%#databinder.eval(...

    u suggest me use this...

    <tr 
    style='<%if (datatype
    == 1) { %> background-color: yellow;  <% }
    else { %> background-color: white;
    <%} %>'>

    Thursday, January 23, 2014 3:17 PM
  • and when i use this shows me error

    Server Error in '/' Application.
    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
    
    Compiler Error Message: CS0103: The name 'datatype' does not exist in the current context
    
    Source Error:
    
    
    Line 122:                            </HeaderTemplate>
    Line 123:                            <ItemTemplate>
    Line 124:                            <tr style='<%if (datatype == 1) { %> background-color: yellow;  <% } else { %> background-color: white; <%} %>'>


    Thursday, January 23, 2014 3:19 PM
  • @Don.O
    Thursday, January 23, 2014 3:47 PM
  • You have a flag in the database called datatype, right?

    So use it as everyother database variable you have there.

    DataBinder.Eval(Container.DataItem, "datatype")

    so the code should look like this

    <tr
    style
    ='<% if (DataBinder.Eval(Container.DataItem, "datatype")== 1) { %> background-color: yellow;  <% }
    else { %> background-color: white;
    <%} %>'
    >


    If you are familiar with the code behind. There is a cleaner way to do this using ItemDataBoundEvent. Let me know if you are interested in doing it that way.
    • Edited by Don.O Thursday, January 23, 2014 3:51 PM
    Thursday, January 23, 2014 3:48 PM
  • i have a documentinfo table and i add column yes_no like this

    so how i set flag in last yes_no column ..is it right or wrong?

    Thursday, January 23, 2014 6:08 PM
  • and when i try your suggested code this shows me error

    Compilation Error 
     Description: An error occurred during the 
    compilation of a resource required to service this request. Please 
    review the following specific error details and modify your source code 
    appropriately.
     Compiler Error Message: CS0103: The name 'Container' does not exist in the current context
    Source Error:
                   
                                  
                   
                      
                          Line 124:<%--                            <tr>--%>
    Line 125:                            <tr
    Line 126:                                  style='<% if (DataBinder.Eval(Container.DataItem, "datatype")== 1) { %> background-color: yellow;  <% }

    Thursday, January 23, 2014 6:17 PM
  • can you please show me the code file that's behind the aspx?
    Thursday, January 23, 2014 6:53 PM
  • ok this is .aspx code

     <div align="center" style="border: thick none #008080; height: 597px; width: 670px;
            color: #000000; font-weight: bold; font-size: medium; font-family: Calibri;">
            <br />
            <br />
            <center>
                <div class="vpb_main_wrapper3" top="20" align="center" style="left: inherit" />
                <br clear="all" />
                <h1 align="center"
                   
                    style="color: #3399FF; font-weight: bolder; font-size: xx-large; font-family: 'Footlight MT Light';">
               DOWNLOAD DOCUMENTS</h1>
                <hr /><hr /><hr /><br /><br />
                <div>
                    
                    <div class="CSSTableGenerator">
                        <table border="0" width="100%" cellpadding="0" cellspacing="0" id="results">
                            <asp:Repeater ID="Repeater1" OnItemCommand="Repeater1_ItemCommand" runat="server">
                                <HeaderTemplate>
                                    <tr>
                                   
                                        <td>
                                        </td>
                                        <%--<td>
                                            Document ID
                                        </td>--%>
                                        <td>
                                            Document Name
                                        </td>
                                        <td>
                                            File Uploaded
                                        </td>
                                        <td>
                                            Uploaded Date
                                        </td>
                                        <td>
                                            Document Type
                                        </td>
                                        <td>
                                            Department Type
                                        </td>
                                        <td>
                                            Approve Name
                                        </td>
                                    </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                              
                                  <tr
                                      style='<%if(DataBinder.Eval(Container.DataItem, "datatype")== 1)
                                    { %> background-color: yellow;  <% }
                                      else { %> background-color: white;
                                       <%} %>'>
                                    <%--<tr class='<%# ((Boolean)Eval("new_indicator")) ? ".new" : ".old" %>'>
                                    <tr class='<%# DataBinder.Eval(Container.DataItem, "ReadFlag") == "1" ? "highlight" : string.Empty %>'>--%>
                                   <%--<td>
                                    
                                    <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#DataBinder.Eval(Container.DataItem, "Status")%>'/>
                                    
                                    </td>--%>
                                   
                                        <td>
                                            <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("FileUploaded") %>'
                                                CommandName="download"  Visible='<%#Convert.ToString(Eval("Status")).ToUpper() != "REJECT" %>' >Download</asp:LinkButton>
                                        </td>
                                        <%--<td>
                                            <%#DataBinder.Eval(Container.DataItem,"DocumentID") %>
                                        </td>--%>
                                        <td>
                                            <%#DataBinder.Eval(Container.DataItem, "DocumentName")%>
                                        </td>
                                        <td>
                                            <%#DataBinder.Eval(Container.DataItem, "FileUploaded")%>
                                        </td>
                                         <td>
                                            <%#DataBinder.Eval(Container.DataItem, "UploadedDate")%>
                                        </td>
                                        <td>
                                            <%#DataBinder.Eval(Container.DataItem, "Document")%>
                                        </td>
                                        <td>
                                            <%#DataBinder.Eval(Container.DataItem, "Department")%>
                                        </td>
                                        <td>
                                            <%#DataBinder.Eval(Container.DataItem, "Status")%>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                </table>
                                </FooterTemplate>
                            </asp:Repeater></table>
                        
                         <div style="overflow: hidden;">
            <asp:Repeater ID="rptPaging" runat="server" onitemcommand="rptPaging_ItemCommand">
                <ItemTemplate>
                                    <asp:LinkButton ID="btnPage"
                     style="padding:8px; margin:2px; background:#20B2AA; border:solid 1px #666; font:8pt tahoma;"
                    CommandName="Page" CommandArgument="<%# Container.DataItem %>"
                     runat="server" ForeColor="White" Font-Bold="True"><%# Container.DataItem %>
                                    </asp:LinkButton>
               </ItemTemplate>
            </asp:Repeater>
            </div>
                    </div>
                </div>
            </center>



    Thursday, January 23, 2014 7:02 PM
  • no I need the vb or cs file sorry if I wasn't clear
    Thursday, January 23, 2014 7:30 PM
  • ok here

      public partial class DownDoc : System.Web.UI.Page
        {
            //DMSLIB.Class1 c1 = new DMSLIB.Class1();
            DMSLIB.Doc docc= new DMSLIB.Doc();
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    BindRepeater();
    
    
                    
                    Repeater1.DataSource = docc.getdocbyuserid(Convert.ToInt32(Session["UserID"]));
                    Repeater1.DataBind();
    
    
                    paneladmin.Visible = false;
    
                    
                    if (Session["UserTypeID"].ToString() == "1")
                    {
                        appdoc.Visible = true;
    
                    }
                    else
                    {
                        appdoc.Visible = false;
    
                    }
                    if (Session["UserDesignationID"].ToString() == "3")
                    {
                        paneladmin.Visible = true;
                    }
                    else
                    {
                        paneladmin.Visible = false;
                    }
                    if (Session["UserDesignationID"].ToString() == "1")
                    {
                       appdoc.Visible = true;
                    }
                    else
                    {
                        appdoc.Visible = false;
                    }
                    if (Session["UserDesignationID"].ToString() == "2")
                    {
                        Managpanel.Visible = true;
                    }
                    else
                    {
                        Managpanel.Visible = false;
                    }
                  
    
    
                 
                    if (Session["UserDesignationID"].ToString() == "3")
                    {
                        Directors.Visible = true;
                    }
                    else
                    {
                        Directors.Visible = false;
                    }
    
    
                }
    
            }
            protected void BindRepeater()
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mydms"].ConnectionString.ToString());
                SqlCommand cmd = new SqlCommand("sphrdoc2", con);
    
                cmd.CommandType = CommandType.StoredProcedure;
    
                cmd.Parameters.AddWithValue("@UserID", Convert.ToInt32(Session["UserID"]));
    
    
    
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                DataTable dt = new DataTable();
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                adp.Fill(dt);
                PagedDataSource pgitems = new PagedDataSource();
                DataView dv = new DataView(dt);
                pgitems.DataSource = dv;
                pgitems.AllowPaging = true;
                pgitems.PageSize = 2;
                pgitems.CurrentPageIndex = PageNumber;
                if (pgitems.PageCount > 1)
                {
                    rptPaging.Visible = true;
                    ArrayList pages = new ArrayList();
                    for (int i = 0; i < pgitems.PageCount; i++)
                        pages.Add((i + 1).ToString());
                    rptPaging.DataSource = pages;
                    rptPaging.DataBind();
                }
                else
                {
                    rptPaging.Visible = false;
                }
                Repeater1.DataSource = pgitems;
                Repeater1.DataBind();
            }
            public int PageNumber
            {
                get
                {
                    if (ViewState["PageNumber"] != null)
                        return Convert.ToInt32(ViewState["PageNumber"]);
                    else
                        return 0;
                }
                set
                {
                    ViewState["PageNumber"] = value;
                }
            }
            protected void rptPaging_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
                BindRepeater();
            }
    
    
            protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                if (e.CommandName == "download")
                {
                    string filename = e.CommandArgument.ToString();
                    string path = MapPath("~/Docfiles/" + filename);
                    byte[] bts = System.IO.File.ReadAllBytes(path);
                    Response.Clear();
                    Response.ClearHeaders();
                    Response.AddHeader("Content-Type", "Application/octet-stream");
                    Response.AddHeader("Content-Length", bts.Length.ToString());
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                    Response.BinaryWrite(bts);
                    Response.Flush();
                    Response.End();
                }
    
    
            }
            protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
        
                if (e.Item.ItemType == ListItemType.AlternatingItem ||
               e.Item.ItemType == ListItemType.Item)
                {
                        
                    DataRowView theDataRowView = e.Item.DataItem as DataRowView;
                    
    
                    // Make sure we got the data row view before we try to use it
                    if (theDataRowView != null)
                    {
                        // Get the value of status from the control that holds the value
                        string theStatus = theDataRowView.Row["Status"].ToString();
    
                        // Find the download link control
                        LinkButton theLinkButtonDownload = e.Item.FindControl("LinkButton1") as LinkButton;
    
                        if (theStatus.ToUpper() == "APPROVE")
                        {
                            if (theLinkButtonDownload != null)
                            {
                                theLinkButtonDownload.Visible = true;
                            }
                        }
                        else
                        {
                            if (theLinkButtonDownload != null)
                            {
                                theLinkButtonDownload.Visible = false;
                            }
                        }
                        
                    }
                }
    
    
            }
        }
    }

    Thursday, January 23, 2014 7:43 PM
  • using System.Web.UI.HtmlControls.HtmlGenericControl 
     
          protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
        
                if (e.Item.ItemType == ListItemType.AlternatingItem ||
               e.Item.ItemType == ListItemType.Item)
                {
                        
                    DataRowView theDataRowView = e.Item.DataItem as DataRowView;
                    
    
                    // Make sure we got the data row view before we try to use it
                    if (theDataRowView != null)
                    {
                        // Get the value of status from the control that holds the value
                        string theStatus = theDataRowView.Row["Status"].ToString();
    
    //Highlight based on yes_no
    var flag = DataBinder.Eval(e.Row.DataItem, "yes_no");
    HtmlGenericControl trHeader= e.Item.FindControl("trHeader") as HtmlGenericControl;
    if(flag==1){
    trHeader.Atributes.Add("style","background-color: yellow");
    }
    
    
    
                        // Find the download link control
                        LinkButton theLinkButtonDownload = e.Item.FindControl("LinkButton1") as LinkButton;
    
                        if (theStatus.ToUpper() == "APPROVE")
                        {
                            if (theLinkButtonDownload != null)
                            {
                                theLinkButtonDownload.Visible = true;
                            }
                        }
                        else
                        {
                            if (theLinkButtonDownload != null)
                            {
                                theLinkButtonDownload.Visible = false;
                            }
                        }
                        
                    }
                }
    
    
    

    ok here is what I would do:

    <table class="CSSTableGenerator" border="0"  cellpadding="0" cellspacing="0" id="results">
                            <asp:Repeater ID="Repeater2" OnItemCommand="Repeater2_ItemCommand"   
                                runat="server" onitemdatabound="Repeater2_ItemDataBound">
                                <HeaderTemplate>
                                    <tr runat="server" id="trHeader" >
                                        
                                       <%-- <td>
                                           DocumentID
                                        </td>--%>
                                        <td>
                                           Document Name
                                        </td>
                                        <td>
                                            File Name
                                        </td>
                                        <td>
                                           Uploaded By
                                        </td>
                                        <td>
                                           Uploaded Date
                                        </td>
                                        <td>
                                            Email
                                        </td>
                                       
                                        <td>
                                            Department
                                        </td>
                                        <td>
                                            Status
                                        
                                        </td>
                                       
                                    </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr runat="server" id="trItem">
                                       
                                        
                                        <asp:HiddenField ID="DocId" runat="server" Value='<%#DataBinder.Eval(Container.DataItem, "DocID")%>' />
    <%--                                    <asp:Label Id="DocId" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DocID")%>'></asp:Label>
    --%>                                    
                                        <td>
                                        <asp:Label Id="DocName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DocumentName")%>'></asp:Label>
                                        </td>
                                        <td>
                                        <asp:Label Id="Uploadfile" runat="server"  Text='<%#DataBinder.Eval(Container.DataItem, "Uploadfile")%>'></asp:Label>
                                        </td>
                                         <td>
                                        <asp:Label Id="Label1" runat="server"  Text='<%#DataBinder.Eval(Container.DataItem, "UploadedBy")%>'></asp:Label>
                                        </td>
                                        <td>
                                        <asp:Label Id="UploadedDate" runat="server"  Text='<%#DataBinder.Eval(Container.DataItem, "UploadedDate")%>'></asp:Label>
                                        </td>
                                         <td>
                                        <asp:Label Id="YourEamil" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "UserEmail")%>'></asp:Label>
                                        </td>
                                        
                                        <td>
                                        <asp:Label Id="DepType" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Department")%>'></asp:Label>
                                        </td>
                                        
                                       
                                    <td>
                                
                                
                                 <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("ApproveID") %>' Visible = "false" />
                                  <asp:HiddenField ID="hfDepartmentId" runat="server" Value='<%# Eval("ApproveID") %>' />
    
    
                            <asp:DropDownList ID="DropDownList4" runat="server" EnableViewState="true" class="vpb_dropdown1" DataTextField="ApproveType" DataValueField="ApproveID" AutoPostBack="true" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged">
                                 <asp:ListItem Text="Pending" selected="selected" Value="3"></asp:ListItem>
                                 <asp:ListItem Text="Approve" Value="1"></asp:ListItem>
                                 <asp:ListItem Text="Reject" Value="2"></asp:ListItem>
                            </asp:DropDownList>
                            </td>
                            </tr>
                            </ItemTemplate>
                                </asp:Repeater>
                                </table> 
                                      
                     
                     <asp:Label ID="Supvisor" runat="server" Font-Size="Medium" ForeColor="Red" ></asp:Label><br />
                     <asp:Label ID="Successz" runat="server" Font-Size="Medium" ForeColor="Green" ></asp:Label><br />
    
                <asp:Button ID="Button1" runat="server"   Text="Submit" onclick="Button1_Click" /> 

    That's just to steer u in the right direction I wrote the code in here not in visual studio so it might have mistakes. It will be even easier if you make the html table an asp table. You van repeat the same thing for the trItem.

    • Proposed as answer by Don.O Friday, January 24, 2014 7:19 PM
    Thursday, January 23, 2014 8:58 PM