好的伙计们,我知道这个问题已被问过一百万次了。我已经搜索了好几天,找不到任何在线解决方案。这是我的代码:
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT VTPNAME, NETWORKKEY, FKVTPDOMAIN, VLANNUMBER, NETDESCRIPTION, BEGINNINGIP,
HOSTS, DEFAULTGATEWAY FROM NETWORK.NETWORK, NETWORK.VTPDOMAIN WHERE
NETWORK.FKVTPDOMAIN = VTPDOMAIN.VTPDOMAINKEY"
DeleteCommand="DELETE FROM NETWORK.NETWORK WHERE NETWORKKEY =: NETWORKKEY"
UpdateCommand="UPDATE NETWORK.NETWORK SET FKVTPDOMAIN =:updateFKVTP, VLANNUMBER = :VLANNUMBER,
NETDESCRIPTION = :NETDESCRIPTION,BEGINNINGIP = :BEGINNINGIP,
HOSTS = :HOSTS,DEFAULTGATEWAY = :DEFAULTGATEWAY WHERE NETWORKKEY = :NETWORKKEY"
InsertCommand="INSERT INTO NETWORK.NETWORK (VLANNUMBER,NETDESCRIPTION,BEGINNINGIP,HOSTS,DEFAULTGATEWAY,FKVTPDOMAIN) VALUES (:vlanNet,:descNet,:begIpNet,:hostNet,:defNet,:vtpdomainkey)">
<InsertParameters>
<asp:ControlParameter Name="vlanNet" ControlID="vlanTextbox" />
<asp:ControlParameter Name="descNet" ControlID="descTextbox" />
<asp:ControlParameter Name="begIpNet" ControlID="beginIPTextbox" />
<asp:ControlParameter Name="hostNet" ControlID="hostsTextbox" />
<asp:ControlParameter Name="defNet" ControlID="defaultGatTextBox" />
<asp:ControlParameter Name="vtpdomainkey" ControlID="vtpDomainFKDropDown" />
</InsertParameters>
<UpdateParameters>
<asp:ControlParameter Name="updateFKVTP" ControlID="vtpNameDropDownUpdate" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView
ID="GridView2"
runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource2"
AllowPaging="True"
AllowSorting="True"
DataKeyNames="NETWORKKEY"
Width="650px"
OnRowUpdating="GridView2_RowUpdating">
<Columns>
<asp:CommandField HeaderText="Options" ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField HeaderText="VTP Domain" SortExpression="VTPNAME">
<EditItemTemplate>
<asp:DropDownList ID="vtpNameDropDownUpdate" runat="server" DataSourceID="SqlDataSource6" DataTextField="VTPNAME" DataValueField="VTPDOMAINKEY">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("VTPNAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
这是给出的实际错误:
Could not find control 'vtpNameDropDownUpdate' in ControlParameter 'updateFKVTP'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not find control 'vtpNameDropDownUpdate' in ControlParameter 'updateFKVTP'.
除了dropDownList之外,一切都按预期工作,。它不会找到它,我已经尝试过美元符号,冒号,下划线,你命名它,告诉它控制在哪里而没有结果。它们是相同的,它们都是一个在另一个之下,正如我在这里发布的那样。我得到了实际更新的第一行,因为我尝试了在运行时右键单击下拉列表的方法,然后检查元素&#34;并将整个ControlID字符串复制并粘贴到ControlParameter ControlID中。问题是,有几行,所以它只适用于我检查的一个元素而不是所有其他元素。任何帮助将不胜感激,并提前感谢您的时间!
-Fernando
答案 0 :(得分:0)
DropDownList位于模板控件中,因此您应首先找到模板控件。在此示例中,模板控件位于Gridview的第7列。在找到模板后,你可以找到DropDownList:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
var index = e.RowIndex;
var dropDownctr= GridView1.Rows[index].Controls[6].FindControl("vtpNameDropDownUpdate")
}