Monday 6 August 2012

nested grid view with sql server code


<asp:GridView runat="server" ID="gvgenericdetails" AutoGenerateColumns="false"
                                                                Font-Names="Verdana" Font-Size="8pt" Width="800px"
                                                                PageSize="3" onrowdatabound="gvgenericdetails_RowDataBound">
                                                                <RowStyle BackColor="#EFF3FB" />
                                                                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                                              
                                                                <HeaderStyle BackColor="#F77A0C" Font-Bold="True" ForeColor="White" Font-Names="Verdana"
                                                                    Font-Size="10pt" HorizontalAlign="Center" />
                                                                <AlternatingRowStyle BackColor="#c4c4c4" />
                                                                <Columns>
                                                                    <asp:TemplateField>
                                                                        <ItemTemplate>
                                                                            <table style="width: 800px; font-size: 8pt" border="0" cellpadding="0" cellspacing="0">
                                                                                <tr>
                                                                                    <td width="500" align="left" valign="middle" height="25">
                                                                                        Generic Name :
                                                                                    </td>
                                                                                    <td width="300" align="left" valign="middle" height="25">
                                                                                        <asp:Label ID="lblGenericName" runat="server" Text='<%#Eval("GenericName")%>'></asp:Label>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td width="500" align="left" valign="middle" height="25">
                                                                                        Strength :
                                                                                    </td>
                                                                                    <td width="300" align="left" valign="middle" height="25">
                                                                                        <asp:Label ID="Label1" runat="server" Text='<%#Eval("Strength")%>'></asp:Label>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td width="500" align="left" valign="middle" height="25">
                                                                                        PackFrom :
                                                                                    </td>
                                                                                    <td width="300" align="left" valign="middle" height="25">
                                                                                        <asp:Label ID="Label2" runat="server" Text='<%#Eval("PackFrom")%>'></asp:Label>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td width="500" align="left" valign="middle" height="25">
                                                                                        Price of Generic :
                                                                                    </td>
                                                                                    <td width="300" align="left" valign="middle" height="25">
                                                                                        <asp:Label ID="Label4" runat="server" Text="Rs."></asp:Label>
                                                                                        <asp:Label ID="Label3" runat="server" Text='<%#Eval("GenericPrice")%>' Font-Bold="True"></asp:Label>
                                                                                        <asp:Label ID="Label5" runat="server" Text="Approx"></asp:Label>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td width="500" align="left" valign="middle" height="25">
                                                                                        Medicine available Free Of Cost at all  Government Hospitals in Rajasthan :
                                                                                    </td>
                                                                                    <td width="300" align="left" valign="middle" height="25">
                                                                                        <asp:Label ID="Label10" runat="server" Text='<%#Eval("AvalStatus")%>' Font-Bold="True"></asp:Label>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr><td colspan="2">
                                                                              <asp:GridView ID="grdbranded" runat="server" AutoGenerateColumns="False"
                                                                                        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
                                                                                        CellPadding="4" ForeColor="Black" GridLines="Horizontal" Width="100%"
                                                                                        HeaderStyle-HorizontalAlign="Left" Font-Size="11px">
                                                                              <Columns>
                                                                            
                                                                                  <asp:BoundField DataField="BrandName" HeaderText="Brand Name" />
                                                                                  <asp:BoundField DataField="ComapnyName" HeaderText="Manufacture By" />
                                                                                  <asp:BoundField DataField="Brandprice" HeaderText="Brand price" />                                                                                 
                                                                                  <asp:BoundField DataField="Form" HeaderText="Form" />
                                                                            
                                                                              </Columns>
                                                                                  <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                                                                                  <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                                                                                  <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                                                                                  <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                                                                                  <SortedAscendingCellStyle BackColor="#F7F7F7" />
                                                                                  <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
                                                                                  <SortedDescendingCellStyle BackColor="#E5E5E5" />
                                                                                  <SortedDescendingHeaderStyle BackColor="#242121" />
                                                                               </asp:GridView>
                                                                               <br /><br />
                                                                               </td></tr>
                                                                            </table>
                                                                        </ItemTemplate>
                                                                   
                                                                   
                                                                    </asp:TemplateField>
                                                                </Columns>
                                                            </asp:GridView>

///------------------------
protected void gvgenericdetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string cGenric = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "GenericName"));
                string cStrength = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Strength"));
                GridView gvChild = (GridView)e.Row.FindControl("grdbranded");
                SqlDataSource gvChildSource = new SqlDataSource();
                gvChildSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                gvChildSource.SelectCommand = "select distinct * from MedicineDetails where GenericName ='" + cGenric + "' and strength='" + cStrength + "' order by brandprice asc";
                gvChild.DataSource = gvChildSource;
                gvChild.DataBind();
            }
        }

No comments:

Post a Comment