how to bind a Grid View in asp.net Programming

How to bind a Grid View in asp.net Programming :

We know the grid view is a more powerful and useful asp.net control.we use grid view for display data in tabular format . grid view provide many properties and methods by which we use this view for different-2 purpose.


How to make grid view by code :

<asp:GridView id="GridView1" runat="server">
</GridView>

by these tow lines code you can get Gridview in your Asp.net web page. there are many properties which is you can use for give look and feel to grid view .as like -
width,height,gridline,font,size,fount color,auto generated colons etc.
know we are try to understand how to bind Grid . for this here we take two GridView.
 ok LET US STATR   :


buind two  Grid and then make a new grid on the using column of these two grid in dynamically .
first Create a grid 1:

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" Visible="false"
                    onrowdatabound="GridView2_RowDataBound">
                 <Columns>
                        <asp:TemplateField HeaderText="HeadID">
                            <ItemTemplate>
                                <asp:Label ID="lblheadID" runat="server" Text= '<%#Eval("HeadID")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="HeadName">
                            <ItemTemplate>
                                <asp:Label ID="lblheadName" runat="server" Text= '<%#Eval("HeadName")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                         <asp:TemplateField HeaderText="FeeType">
                            <ItemTemplate>
                                <asp:Label ID="lblFeeType" runat="server" Text='<%#Eval("FeeType")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Amount">
                            <ItemTemplate>
                                <asp:Label ID="lblAmount" runat="server" Text='<%#Eval("Amount")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="TotalAmount">
                            <ItemTemplate>
                                <asp:Label ID="lbltotalAmount" runat="server" ></asp:Label>
                          </ItemTemplate>
                        </asp:TemplateField>
                         </Columns>
                </asp:GridView>


Code for buinding this Grid 1 :

DataSet  dshead=new DataSet();
  dshead = _objfee.Select_EstimatedAmountbyInstallmentIDfromdefineAmount(Convert.ToInt32(ddlmonth.SelectedValue), Convert.ToInt32(ddlclassId.SelectedValue));
                GridView1.DataSource = dshead;
                GridView1.DataBind();


Make Second Grid :
 <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="false" Visible="false"
                    Width="301px">
                  <Columns>
                        <asp:TemplateField HeaderText="HeadID">
                            <ItemTemplate>
                                <asp:Label ID="lblHeadName" runat="server" Text= '<%#Eval("HeadName")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                         <asp:TemplateField HeaderText="ConAmount">
                            <ItemTemplate>
                                <asp:Label ID="lblConAmount" runat="server" Text='<%#Eval("ConAmount")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="PaidAmount">
                            <ItemTemplate>
                                <asp:Label ID="lblPaidAmount" runat="server" Text='<%#Eval("PaidAmount")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                         </Columns>
                </asp:GridView>

Code for binding second Grid:

DataSet ds1 = new DataSet();
                ds1 = _objfee.Select_EstimatedAmountbyInstallmentIDfromPaidAmount(Convert.ToInt32(ddlmonth.SelectedValue), Convert.ToInt32(ddlclassId.SelectedValue));
                GridView2.DataSource = ds1;
                GridView2.DataBind();

Comments

Popular posts from this blog