<asp:GridView ID="Admin_Grid" runat="server" AutoGenerateColumns="False" CellPadding="4" OnRowCancelingEdit="Admin_Grid_RowCancelingEdit" OnRowEditing="Admin_Grid_RowEditing" OnRowUpdating="Admin_Grid_RowUpdating" ForeColor="#333333" GridLines="None" OnRowDataBound="Admin_Grid_RowDataBound"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:TemplateField HeaderText="FirstName"> <ItemTemplate> <asp:Label ID="lbl_FName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txt_FName" runat="server" Text='<%#Eval("FirstName") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="LastName"> <ItemTemplate> <asp:Label ID="lbl_LName" runat="server" Text='<%#Eval("LastName") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txt_LName" runat="server" Text='<%#Eval("LastName") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Organization"> <ItemTemplate> <asp:Label ID="lbl_Organization" runat="server" Text='<%#Eval("Organization") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txt_Organization" runat="server" Text='<%#Eval("Organization") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="PhoneNumber"> <ItemTemplate> <asp:Label ID="lbl_PhoneNumber" runat="server" Text='<%#Eval("PhoneNumber") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txt_PhoneNumber" runat="server" Text='<%#Eval("PhoneNumber") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="EmailAddress"> <ItemTemplate> <asp:Label ID="lbl_EmailAddress" runat="server" Text='<%#Eval("EmailAddress") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txt_EmailAddress" runat="server" Text='<%#Eval("EmailAddress") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText = "AIPServed"> <ItemTemplate> <asp:Label ID="lbl_AIPServed" runat="server" Text='<%# Eval("AIPServed")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:ListBox ID="ListBoxAIPServed" runat="server"></asp:ListBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText = "UserStatus"> <ItemTemplate> <asp:Label ID="lbl_Status" runat="server" Text='<%# Eval("UserStatus")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label ID="lbl_Status" runat="server" Text='<%# Eval("UserStatus")%>' Visible = "false"></asp:Label> <asp:DropDownList ID = "ddl_Status" runat = "server"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText = "City"> <ItemTemplate> <asp:Label ID="lblCity" runat="server" Text='<%# Eval("APCUserID")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label ID="lblCity" runat="server" Text='<%# Eval("APCUserID")%>' Visible = "false"></asp:Label> <asp:DropDownList ID = "ddlCities" runat = "server"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True" /> </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#507CD1" ForeColor="#ffffff" Font-Bold="True"/> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB"/> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView>
protected void Admin_Grid_RowDataBound(object sender, GridViewRowEventArgs e) { DropDownList ddlCities = (DropDownList)e.Row.FindControl("ddlCities"); DataTable table = new DataTable(); table.Columns.Add("APCUserID"); //table.Columns.Add("FirstName"); // APCUserID,FirstName,LastName,Organization,PhoneNumber,EmailAddress,AIPServed,UserID,Password,UserStatus //var lines = System.IO.File.ReadAllLines("test.txt"); //System.IO.File.WriteAllLines("test.txt", lines.Take(lines.Length - 1).ToArray()); using (StreamReader sr = new StreamReader(@"C:\Working\US_Crop\Sowmya\USCROP\AgencyProfitCommissionWebApplication\APSDataAccess\Resources\AIPlist.txt")) { while (!sr.EndOfStream) { string[] parts = sr.ReadLine().Split(','); table.Rows.Add(parts[0]); } } ddlCities.DataSource = table; ddlCities.DataTextField = "APCUserID"; ddlCities.DataValueField = "APCUserID"; ddlCities.DataBind(); ddlCities.Items.FindByValue((e.Row.FindControl("lblCity") as Label).Text).Selected = true; }
"Object reference not set to an instance of an object."
null
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)