如何在网格视图中获得动态创建的下拉所选文本
问题描述:
我需要在gridview中找到动态创建的下拉列表的选定文本.请帮忙.
Hi,
I need to find selected text of dynamically created dropdown in gridview.Please help.
答
首先,您必须动态创建一个下拉列表并将其添加到gridview编辑临时字段中在gridview行中创建的事件
然后在行命令事件中找到像
这样的dropdownlis控件
First you have to create a dropdown list dynamically and add it to gridview edit tempalte field in gridview row created event
then on row command event find that dropdownlis control like
If e.CommandName = "Edit" Then
Dim i As Integer = e.CommandArgument
Dim row As GridViewRow = GridView2.Rows(i)
Dim dd As DropDownList
dd= DirectCast(row.FindControl("ddl1"), DropDownList)
End If
可能会帮助您
it may help you
尝试此操作,首先获取一个模板字段,然后添加项目模板,然后在编辑模板内部将下拉列表如下...
try this ,first take a template field then add item template,then inside edit template put the dropdown as follow...
<asp:templatefield headertext="Status" sortexpression="with_status" xmlns:asp="#unknown">
<itemtemplate>
<asp:label id="Label1" runat="server" text="<%# Bind("with_status") %>"></asp:label>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem value="0">-Select- </asp:listitem>
<asp:listitem value="1">pending </asp:listitem>
<asp:listitem value="2">completed </asp:listitem>
</asp:dropdownlist>
</edititemtemplate>
</asp:templatefield>
aspx.cs
在rowupdating上输入以下代码
aspx.cs
on rowupdating put the following code
DropDownList ddl2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1");
if (ddl2.SelectedValue.ToString() != "0")
{
SqlDataSource1.UpdateParameters["with_status"].DefaultValue = ddl2.SelectedItem.ToString();
}