Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make this DropDownList works inside the GridView?
    text
    copied!<p>I have two tables in my database as following:</p> <p>Suggestions Table: ID, Title, Description, StatusID... etc</p> <p>SuggestionsStatus Table: ID, Status</p> <p>I am using GridView to show the Suggestions and in the last column I put a DropDownList that for selecting the status for each Suggestion. Now, when I tried to show the Status in the DropDownList, I got the following error and I don't know why:</p> <blockquote> <p>An object reference is required for the non-static field, method, or property 'System.Web.UI.WebControls.ListControl.Items.get'</p> </blockquote> <p>My ASP.NET code:</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" width="950px" CssClass="mGrid" AlternatingRowStyle-CssClass="alt" RowStyle-HorizontalAlign="Center" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" &gt; &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt; &lt;HeaderStyle Font-Bold = "true" ForeColor="Black" Height="20px"/&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /&gt; &lt;asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /&gt; &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /&gt; &lt;asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /&gt; &lt;asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" /&gt; &lt;asp:BoundField DataField="DivisionShortcut" HeaderText="Division" SortExpression="DivisionShortcut" /&gt; &lt;asp:TemplateField HeaderText="Status"&gt; &lt;ItemTemplate&gt; &lt;asp:DropDownList ID="DropDownList" runat="server" DataSourceID="SqlDataSource2" Font-Bold="True" ForeColor="#006666" AppendDataBoundItems="false" DataTextField="Status" DataValueField="ID" AutoPostBack="true" OnDataBound="DropDownList_DataBound"&gt; &lt;/asp:DropDownList&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;" SelectCommand="SELECT dbo.SafetySuggestionsLog.ID, dbo.SafetySuggestionsLog.Title, dbo.SafetySuggestionsLog.Description, dbo.employee.Name, dbo.SafetySuggestionsLog.Username, dbo.Divisions.DivisionShortcut FROM dbo.employee INNER JOIN dbo.SafetySuggestionsLog ON dbo.employee.Username = dbo.SafetySuggestionsLog.Username INNER JOIN dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode" FilterExpression="[DivisionShortcut] like '{0}%'"&gt; &lt;FilterParameters&gt; &lt;asp:ControlParameter ControlID="ddlDivision" Name="DivisionShortcut" PropertyName="SelectedValue" Type="String" /&gt; &lt;/FilterParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;%--For the DropDownList--%&gt; &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;" SelectCommand="SELECT * FROM [SafetySuggestionsStatus]"&gt;&lt;/asp:SqlDataSource&gt; </code></pre> <p>My Code-Behind:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { } int i = 1; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Text = i.ToString(); i++; } } protected void DropDownList_DataBound(object sender, EventArgs e) { if (!IsPostBack) { DropDownList.Items.Insert(0, new ListItem("--Select--", "")); } } </code></pre> <p><strong>So how I can fix this problem?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload