如何根据数据库中的值显示Gridview

时间:2015-08-24 10:00:44

标签: c# asp.net sql-server

我想根据TypeOfServices检查ClientId中的服务,并检查所有服务。

数据库列为TaxId, ClientId, ClientName,TypeOfservice

gridview应按字母顺序显示客户名称,并且显示的服务应显示“是”否则为“否”

我使用了这个C#代码,但它不能正常工作......

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label lblclientname = (Label)e.Row.FindControl("lblclientname");

        Label lblincometax = (Label)e.Row.FindControl("lblincometax");
        Label lblprofessionaltax = (Label)e.Row.FindControl("lblprofessionaltax");
        Label lblservicetax = (Label)e.Row.FindControl("lblservicetax");
        Label lbltds = (Label)e.Row.FindControl("lbltds");
        Label lblvat = (Label)e.Row.FindControl("lblvat");
        Label lblcompanylaw = (Label)e.Row.FindControl("lblcompanylaw");

        string m = "SELECT * FROM tblTaxMaster";
        ds = gs.getdata(m);
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                string ClientId = ds.Tables[0].Rows[0]["ClientId"].ToString();
                string TaxId = ds.Tables[0].Rows[0]["TaxId"].ToString();

                string ser = "select TypeOfService from tblTaxMaster where ClientId= '" + ClientId.ToString() + "' and TaxId = '" + TaxId.ToString() + "' ";
                ds = gs.getdata(ser);

                if (ser == "INCOME TAX")
                {
                    lblincometax.Text = "YES";
                }
                else
                {
                    lblincometax.Text = "NO";
                }

                if (ser == "TDS")
                {
                    lbltds.Text = "YES";
                }
                else
                {
                    lbltds.Text = "NO";
                }
                if (ser == "PROFESSIONAL TAX")
                {
                    lblprofessionaltax.Text = "YES";
                }
                else
                {
                    lblprofessionaltax.Text = "NO";
                }
                if (ser == "SERVICE TAX")
                {
                    lblservicetax.Text = "YES";
                }
                else
                {
                    lblservicetax.Text = "NO";
                }
                if (ser == "VAT")
                {
                    lblvat.Text = "YES";
                }
                else
                {
                    lblvat.Text = "NO";
                }
                if (ser == "COMPANY LAW")
                {
                    lblcompanylaw.Text = "YES";
                }
                else
                {
                    lblcompanylaw.Text = "NO";
                }
            }
        }
    }
}

这是ASP.Net代码

    <asp:GridView ID="GridView1" runat="server" Width="550px" 
    AutoGenerateColumns="False" Font-Names="Cambria" Font-Size="10pt" 
     ShowFooter="True"   FooterStyle-BackColor="#FF5600"
    CellPadding="4" CssClass="grid-view"  PageSize="20" 
     GridLines="None" ForeColor="#333333" onrowdatabound="GridView1_RowDataBound">

                    <AlternatingRowStyle BackColor="White" />

                    <Columns>
                      <asp:TemplateField ItemStyle-Width="30px" HeaderText="Client Name">
                            <ItemTemplate>
                                <asp:Label ID="lblclientname" runat="server" Text='<%#Eval("ClientName")%>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>

                  <asp:TemplateField ItemStyle-Width="30px" HeaderText="Income Tax">
                            <ItemTemplate>
                                <asp:Label ID="lblincometax" runat="server"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>

                         <asp:TemplateField ItemStyle-Width="30px" HeaderText="Professional Tax">
                            <ItemTemplate>
                                <asp:Label ID="lblprofessionaltax" runat="server"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>

                         <asp:TemplateField ItemStyle-Width="30px" HeaderText="Service Tax">
                            <ItemTemplate>
                                <asp:Label ID="lblservicetax" runat="server"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>

                         <asp:TemplateField ItemStyle-Width="30px" HeaderText="TDS">
                            <ItemTemplate>
                                <asp:Label ID="lbltds" runat="server"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>

                         <asp:TemplateField ItemStyle-Width="30px" HeaderText="VAT">
                            <ItemTemplate>
                                <asp:Label ID="lblvat" runat="server"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>

                        <asp:TemplateField ItemStyle-Width="30px" HeaderText="Company Law">
                            <ItemTemplate>
                                <asp:Label ID="lblcompanylaw" runat="server"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>  

                        <asp:TemplateField ItemStyle-Width="30px" HeaderText="">
                            <ItemTemplate>
                                <asp:Button ID="btnservicedetails" runat="server" Text="Service Details" />
                            </ItemTemplate>
                            <ItemStyle Width="30px"></ItemStyle>
                        </asp:TemplateField>  



                    </Columns>
                    <EditRowStyle BackColor="#333333" />
                    <FooterStyle BackColor="#191919" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#191919" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#E6E6E6" />
                    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#F8FAFA" />
                    <SortedAscendingHeaderStyle BackColor="#246B61" />
                    <SortedDescendingCellStyle BackColor="#D4DFE1" />
                    <SortedDescendingHeaderStyle BackColor="#15524A" />

                    </asp:GridView>

0 个答案:

没有答案