Wednesday 27 August 2014

Generate Dynamic table in html format in .cs page | Table Report | Design Report in asp.net with c#

Hi Everyone  in this article i am going to show how to generate dynamic table or we can say clone of grid view
with code behind .
we dont need to add any new control just apply css on code behind page and generate table with data.
i have shown both example with grid view and aslo with dynamic generated table with examples code.


0-> declare public string strDisplayDynamicTableReport = ""; before page load
1-> to take public string so we can assign string and then append on .aspx page like server control.
2-> We can bind our declare css also.
strDisplayDynamicTableReport += "<table cellpadding='0' cellspacing='0' border='1' bordercolor='red' >";
3->count table rows

for (int cnt = 0; cnt < DtGetAllEmoRecord.Rows.Count; cnt++)

4-> while  there is record in table add record in string and then print in html format.
by adding .aspx page

             <div>

                        <%=strDisplayDynamicTableReport%>

                  </div>


code for gridview


<asp:GridView runat="server" ID="grddata" AllowPaging="True" AutoGenerateColumns="false" DataKeyNames="NAME">
      <Columns>
          <asp:BoundField DataField="NAME" HeaderText="Name" ReadOnly="True"
              SortExpression="NAME" />
               <asp:BoundField DataField="NUMBER" HeaderText="Number" ReadOnly="True"
              SortExpression="NUMBER" />
               <asp:BoundField DataField="MAIL" HeaderText="Email Id" ReadOnly="True"
              SortExpression="MAIL" />
              <asp:TemplateField HeaderText="Delete">
              <ItemTemplate>
              <asp:LinkButton runat="server" ID="lnkdele" Text="delete" OnClick="lnkdele_click"></asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateField>
                <asp:TemplateField HeaderText="Edit">
              <ItemTemplate>
              <asp:LinkButton runat="server" ID="lnkedit" Text="Edit" OnClick="lnkedit_click"></asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateField>
      </Columns>
      <EmptyDataRowStyle BackColor="#FF9999" BorderStyle="Dashed" />
     
    </asp:GridView>



just call below function on page load or any control event..




private void DiplayAllREcord()
    {
       
        SqlDataAdapter sda = new SqlDataAdapter("Sp_InsertUpadetData 'SELECT','','','',''", sqcon);
        DataTable DtGetAllEmoRecord = new DataTable();
        sda.Fill(DtGetAllEmoRecord);
      
       if (DtGetAllEmoRecord != null && DtGetAllEmoRecord.Rows.Count > 0)
        {
            strDisplayDynamicTableReport += "<div id='UserDetails'>";
            strDisplayDynamicTableReport += "<table cellpadding='0' cellspacing='0' border='1' bordercolor='red' >";
            strDisplayDynamicTableReport += "<tr>";
            strDisplayDynamicTableReport += "<td width='150'><b>Employee Name:</b> </td>";
            strDisplayDynamicTableReport += "<td width='150'><b>Employee Number:</b> </td>";
            strDisplayDynamicTableReport += "<td width='150'><b>Employee Email:</b> </td>";
            strDisplayDynamicTableReport += "</tr>";
            for (int cnt = 0; cnt < DtGetAllEmoRecord.Rows.Count; cnt++)
            {
              
                strDisplayDynamicTableReport += "<tr>";
                strDisplayDynamicTableReport += "<td width='200'>" + DtGetAllEmoRecord.Rows[cnt]["NAME"].ToString() + "</td>";
                strDisplayDynamicTableReport += "<td width='200'>" + DtGetAllEmoRecord.Rows[cnt]["NUMBER"].ToString() + "</td>";
                strDisplayDynamicTableReport += "<td width='200'>" + DtGetAllEmoRecord.Rows[cnt]["MAIL"].ToString() + "</td>";
                strDisplayDynamicTableReport += "</tr>";
               
            }
            strDisplayDynamicTableReport += "</table>";
            strDisplayDynamicTableReport += "</div>";
        }
        grddata.DataSource = DtGetAllEmoRecord;
        grddata.DataBind();
       
 
    }



Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: