如何在编辑项模板中填充下拉列表中的选定值 [英] How to populate drop down list selected values in edit item template
本文介绍了如何在编辑项模板中填充下拉列表中的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai,
我有一个gridview。在gridview中有一个优先级列。在< edititemtemplate>我正在使用下拉列表的优先级。如果我选择编辑按钮它没有显示所选的下拉值.Plz帮助我。
提前谢谢。
Hai,
I have a gridview.In the gridview there is a priority column.In the <edititemtemplate> of the priority I am using dropdown list.Suppose if i select edit button it is not showing the selected drop down values.Plz help me.
Thanks in advance.
推荐答案
您需要设置EditIndex。
看看这个。
这可能有助于你
填充-的DropDownList与 - 选择 - 值在-EditItemTemplate中-的-GridView的功能于ASPNet.aspx [ ^ ]
You need to set the EditIndex.
Have a look at this.
This might help u
Populate-DropDownList-with-Selected-Value-in-EditItemTemplate-of-GridView-in-ASPNet.aspx[^]
将下拉列表添加到edittemplate,如下所示
add drop down list to edittemplate as following
<asp:Gridview AutoGenerateColumns="false" ID="gv" OnRowEditing="Row_Edit" ...................>
<Columns>
------------------------
------------------------
<asp:TemplateField>
<ItemTemplate>
// add label to show data
</ItemTemplate>
<EditTemplate>
<asp:DropdownList ID="ddl" runat="server">
<asp:ListItem Text="Select" Value="0" />
</asp:DropdownList>
</EditTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>
Plz尝试以下代码它真的对你有帮助因为我已经在我的申请....
$。b $ b.bp页面上的代码
---------------- -----------------------------
Plz try below code it's really helping to you becz i already made it in my application....
code on .aspx page
---------------------------------------------
<asp:TemplateField HeaderText="Location">
<ItemTemplate>
<asp:Label ID="lbllocation" runat="server" Text='<%#Bind("location") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblloc" runat="server" Text='<%#Bind("location") %>' Visible="false"></asp:Label>
<asp:DropDownList ID="drploc" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
------ ----------------------------------------
.aspx.cs页面上的代码
----------------------------- -----------------
----------------------------------------------
Code on .aspx.cs page
----------------------------------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
//Code for binding dropdown on selected index of edit
Label lblloc = (Label)e.Row.FindControl("lblloc");
DropDownList drploc = (DropDownList)e.Row.FindControl("drploc");
DataSet ds = new DataSet();
ds = rb.Fill_Location();
if (ds.Tables[0].Rows.Count != 0)
{
drploc.DataSource = ds.Tables[0];
drploc.DataTextField = "location";
drploc.DataValueField = "location_id";
drploc.DataBind();
}
drploc.Items.FindByText(lblloc.Text).Selected = true;
}
}
}
这篇关于如何在编辑项模板中填充下拉列表中的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文