0
我有一个GridView的下拉列表(其实有一堆),但我只关心其中的一个。当用户进行新选择时,我需要捕获它们是否要将项目添加到下拉列表中。这里是我的代码..没有捕获SelectedIndexChanged
这不会被调用:
protected void DebtorDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.Rows[GridView1.EditIndex];
DropDownList list = (DropDownList)row.FindControl("DebtorDropDownList");
string temp = list.SelectedValue;
}
这里是ASP代码:
<ItemTemplate>
<asp:DropDownList ID="DebtorDropDownList" AppendDataBoundItems="true" runat="server"
DataSourceID="SqlDataSource4" DataTextField="FirstName" DataValueField="contactkey"
SelectedIndexChanged="DebtorDropDownList_SelectedIndexChanged" AutoPostBack="True" >
<asp:ListItem Selected="True">Select</asp:ListItem>
<asp:ListItem >Add New Contact</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:AuditDevConnectionString2 %>"
SelectCommand="sp_fc_vm_getSpokeTo" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" DefaultValue="0" Name="DebtorKey"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
我缺少什么?我是否也使用正确的代码来找到正确的控件?
你是否为整个'
我想你的回传,你的下拉列表重新绑定。你为什么不在Gridview itemCommand中捕获这个值?将您的sqldatasource移出griview – 2011-12-21 22:47:34
我发现我的问题。如果你仔细看看我的ASP,你会注意到“SelectedIndexChanged”事件缺少“On”。一旦我补充说,事情按预期工作。 – Craig 2011-12-22 03:17:01