无法动态创建动态网格视图控件中的控件

时间:2014-09-20 11:38:29

标签: c# asp.net

asp.net代码

<asp:GridView ID="GridView1" Width="100%" runat="server" CssClass=" table table-bordered" RowStyle-HorizontalAlign="Center" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
            <Columns>
                <asp:TemplateField HeaderText="Field office">
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server">
                            <asp:ListItem>--Select Field--</asp:ListItem>
                            <asp:ListItem>Ahmedabad</asp:ListItem>
                            <asp:ListItem>Ahmedabad-2</asp:ListItem>
                            <asp:ListItem>Bangalore</asp:ListItem>
                            <asp:ListItem>Bangalore-2</asp:ListItem>
                            <asp:ListItem>Bangalore-3</asp:ListItem>
                            <asp:ListItem>Bhubaneshwar</asp:ListItem>
                            <asp:ListItem>Chennai</asp:ListItem>
                            <asp:ListItem>Cochin</asp:ListItem>
                            <asp:ListItem>Delhi</asp:ListItem>
                            <asp:ListItem>Guwahati</asp:ListItem>
                            <asp:ListItem>Guwahati-2</asp:ListItem>
                            <asp:ListItem>Hyderabad</asp:ListItem>
                            <asp:ListItem>Indore</asp:ListItem>
                            <asp:ListItem>Jaipur</asp:ListItem>
                            <asp:ListItem>Kolhapur</asp:ListItem>
                            <asp:ListItem>Kolkata</asp:ListItem>
                            <asp:ListItem>Lucknow</asp:ListItem>
                            <asp:ListItem>Ludhiana</asp:ListItem>
                            <asp:ListItem>Mumbai 1</asp:ListItem>
                            <asp:ListItem>Mumbai 2</asp:ListItem>
                            <asp:ListItem>Madurai</asp:ListItem>
                            <asp:ListItem>Nagpur</asp:ListItem>
                            <asp:ListItem>Patna</asp:ListItem>
                            <asp:ListItem>Pune</asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Field Center ">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Segment">
                    <ItemTemplate>
                        <%--<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>--%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="SS ">
                    <ItemTemplate>
                        <%--<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>--%>
                        <%--<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>--%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Productivity">
                    <ItemTemplate>
                        <%--<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>--%>
                        <%--<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>--%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Rate">
                    <ItemTemplate>
                        <%--<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>--%>
                        <%--<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>--%>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="White" ForeColor="#000066" />
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
            <RowStyle ForeColor="#000066" />
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#007DBB" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#00547E" />
        </asp:GridView>

C#代码

int subrows1 = Convert.ToInt32(Session["seg"].ToString());
 int rows1 = Convert.ToInt32(Session["fno"].ToString());
        try
        {
            for (int i = 0; i < rows1; i++)
            {
   DropDownList dl = (DropDownList)GridView1.Rows[i].Cells[0].FindControl("DropDownList1");
     TextBox tx = (TextBox)GridView1.Rows[i].FindControl("TextBox1");
                string a = tx.Text;
                string b = dl.SelectedItem.Text;               
               for (int j = 0; j < subrows1; j++)
                {
              TextBox txt = (TextBox)GridView1.Rows[j].FindControl("txt" + j);
              //Label l = (Label)GridView1.Rows[i].Cells[2].FindControl("lbl" + j);
              //TextBox t = (TextBox)GridView1.Rows[i].Cells[3].FindControl("txt" + j);
              //TextBox t1 = (TextBox)GridView1.Rows[i].Cells[4].FindControl("txt1" + j);
              //TextBox t2 = (TextBox)GridView1.Rows[i].Cells[5].FindControl("txt2" + j);

               Label l = (Label)GridView1.Rows[i].FindControl("lbl0");
               TextBox t = (TextBox)GridView1.Rows[i].FindControl("txt0");
               TextBox t1 = (TextBox)GridView1.Rows[i].FindControl("txt1" + j + "_" + j);
               TextBox t2 = (TextBox)GridView1.Rows[i].FindControl("txt2" + j + "_" + j);


                }
}

0 个答案:

没有答案