GridView模板嵌套DropDownList+SqlDataSource的问题
<asp:GridView ID="GridView1" runat="server" Width="650px" AllowPaging="True" PageSize="5" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
<RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle BackColor="#404040" Font-Bold="True" Font-Names="Arial" ForeColor="White"
HorizontalAlign="Center" VerticalAlign="Middle" />
<AlternatingRowStyle BackColor="Silver" />
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:TemplateField HeaderText="机型ID" SortExpression="MachineID">
<EditItemTemplate>
<asp:DropDownList ID="TextBox1" DataSourceID="dsMachine" DataTextField="machinename" DataValueField="id" runat="server" > </asp:DropDownList>
<asp:SqlDataSource ID="dsMachine" runat="server" ConnectionString=" <%$ ConnectionStrings:ERPConnectionString %> " SelectCommand="SELECT [ID], [MachineName] FROM [Machines]"> </asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text=' <%# Bind("MachineID") %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
.................后面是一系列的模板列..
<asp:CommandField HeaderText="编辑" ShowEditButton="True" ShowHeader="True" />
<asp:ButtonField CommandName="Delete" HeaderText="删除" ShowHeader="True" Text="删除" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" <%$ ConnectionStrings:ERPConnectionString %> "
SelectCommand="uPCB_GetAllPCBRecord" SelectCommandType="StoredProcedure" UpdateCommand="uPCB_UpdatePCBRecord" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:ControlParameter ControlID="TextBox1" Name="machineid" PropertyName="SelectedValue" Type="String" />
<asp:Parameter Name="version" Type="String" />
<asp:Parameter Name="SupplySide" Type="String" />
<asp:Parameter Name="SignBillDate" Type="DateTime" />
<asp:Parameter Name="SignBillNum" Type="Int32" />
<asp:Parameter Name="HandedNum" Type="Int32" />
<asp:Parameter Name="unHandedNum" Type="Int32" />
<asp:Parameter Name="sendeddate" Type="DateTime" />
<asp:Parameter Name="actualdate" Type="DateTime" />
<asp:Parameter Name="remark" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
此代码的问题是找不到GridView模板中的控件TextBox1.
运行时错误是:
未能在 ControlParameter“machineid”中找到控件“TextBox1”。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: 未能在 ControlParameter“machineid”中找到控件“TextBox1”。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[InvalidOperationException: 未能在 ControlParameter“machineid”中找到控件“TextBox1”。]
System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +383
System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +70
System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +134
System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +89
System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +344
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +451
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1140
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +835
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +107
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +175
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839
请专家解答...
[解决办法]
晕了,不如说说你怎么实现的,问题处在那里,别人的实现方法
[解决办法]
你的id在哪里啊?我则么看不见?你再复制请楚一点!