我读了一些其他线程,并没有为我工作= \ 我有一个GridView
与DropDownList
在一个字段中。我想知道如何为此设置DataSource
?我没有使用模板既不ItemTemplate或EditItemTemplate我不知道它是如何工作的,所以我还没有使用它。如何将DataSource设置为DropDownList?
到目前为止,我只创建了GridView并填充了数据字段,但我不知道如何为DropDownList
做同样的事情。缺少的东西我想,这是给我一个错误("The Reference of the Object was not set as an instance of an object"
)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList Drop_Prioridades = (DropDownList)e.Row.FindControl("Drop_Prioridades");
Drop_Prioridades.DataTextField = "BAIXA";
Drop_Prioridades.DataValueField = "1";
Drop_Prioridades.DataTextField = "MEDIA";
Drop_Prioridades.DataValueField = "2";
Drop_Prioridades.DataTextField = "ALTA";
Drop_Prioridades.DataValueField = "3";
Drop_Prioridades.DataBind();
}
我也试过这种/同样的错误= \
DataSet ds = func.LoadPriority();
foreach (DataRow row in ds.Tables[0].Rows)
{
ListItem item = new ListItem();
item.Text = row["prioridade"].ToString();
item.Value = row["id"].ToString();
DropDownList ddlPrioridades = (DropDownList)e.Row.FindControl("Drop_Prioridades");
ddlPrioridades.Items.Add(item);
}
,并试图这也太...
HTML :
<columns>
<asp:TemplateField HeaderText="PRIORIDADE" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:DropDownList ID="Drop_Prioridades" Width="120px" runat="server" ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
代码背后:
个DataSet ds = func.CarregaPrioridade();
DropDownList ddlist = (DropDownList)e.Row.FindControl("Drop_Prioridades");
ddlist.DataSource = ds;
ddlist.DataTextField = "prioridade";
ddlist.DataValueField = "id";
更好的表现出一定的代码。你有什么尝试? – Ofiris
尝试在这里进行搜索[.NET示例吨](http://www.google.com) – MethodMan
我编辑了帖子。这就是我到目前为止= \ 我已经在那里搜索,我仍然在做...谢谢 – Ghaleon