我讀了一些其他線程,並沒有爲我工作= \ 我有一個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