ASP.net GridView未从FooterTemplate插入
我卡住了。我实现了将GridView FooterTemplate中的复选框和文本框控件中的新DB值插入SQLDataSource所需的所有步骤,但是当我单击我的Add按钮启动insert命令时,我的页面会闪烁,并且不会发生插入。就实际的SQL而言,我将一个存储过程设置为GridView的数据源的insert操作。我已经单独测试了这个程序,它工作得很好 我的设计基于本文:我的错误可能在我的事件处理程序中的某个地方。知道我错过了什么吗 发布所有GridView代码可能太长,因此以下是要点: “插入”按钮的页脚模板:ASP.net GridView未从FooterTemplate插入,asp.net,gridview,Asp.net,Gridview,我卡住了。我实现了将GridView FooterTemplate中的复选框和文本框控件中的新DB值插入SQLDataSource所需的所有步骤,但是当我单击我的Add按钮启动insert命令时,我的页面会闪烁,并且不会发生插入。就实际的SQL而言,我将一个存储过程设置为GridView的数据源的insert操作。我已经单独测试了这个程序,它工作得很好 我的设计基于本文:我的错误可能在我的事件处理程序中的某个地方。知道我错过了什么吗 发布所有GridView代码可能太长,因此以下是要点: “插入
是的,事件处理程序没有连接
<asp:GridView ID="CartonGridView" runat="server" AutoGenerateColumns="False"
CellPadding="6" DataKeyNames="CartonID" Width="100%"
DataSourceID="Carton_Table" ForeColor="#333333"
GridLines="None" AllowSorting="True"
onrowcommand="CartonGridView_RowCommand">
sqldatasource的SQLINSERT命令在哪里?可能是有错误?@Aristos-我添加了指定GridView对insert过程引用的代码,但正如我前面所说的,SP本身工作正常。就是这样!非常感谢gbs。为了记录在案,我还必须将OnInsert处理程序连接到我的Carton_表上。
<asp:SqlDataSource ID="Carton_Table" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
InsertCommand="spCartonInsert" InsertCommandType="StoredProcedure"
SelectCommand="spCartonSelect" SelectCommandType="StoredProcedure"
UpdateCommand="spCartonUpdate" UpdateCommandType="StoredProcedure">
...
<InsertParameters>
<asp:Parameter Name="Active" Type="Boolean" />
<asp:Parameter Name="Value" Type="String" />
<asp:Parameter Name="Description" Type="String" />
</InsertParameters>
protected void CartonGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
CheckBox Active = CartonGridView.FooterRow.FindControl("InsertActive") as CheckBox;
TextBox SAPCode = CartonGridView.FooterRow.FindControl("InsertSAPCode") as TextBox;
TextBox Description = CartonGridView.FooterRow.FindControl("InsertDescription") as TextBox;
SqlParameter paramActive = new SqlParameter("@Active", SqlDbType.Bit);
paramActive.Direction = ParameterDirection.Input;
paramActive.Value = Active.Checked;
insertParameters.Add(paramActive);
SqlParameter paramValue = new SqlParameter("@Value", SqlDbType.NVarChar, 30);
paramValue.Direction = ParameterDirection.Input;
paramValue.Value = paramValue.Text;
insertParameters.Add(paramValue);
SqlParameter paramDescription = new SqlParameter("@SAP_Long_Description", SqlDbType.NVarChar, 250);
paramDescription.Direction = ParameterDirection.Input;
paramDescription.Value = Description.Text;
insertParameters.Add(paramDescription);
Carton_Table.Insert();
}
}
protected void Carton_Table_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters.Clear();
foreach (SqlParameter p in insertParameters)
e.Command.Parameters.Add(p);
}
<asp:GridView ID="CartonGridView" runat="server" AutoGenerateColumns="False"
CellPadding="6" DataKeyNames="CartonID" Width="100%"
DataSourceID="Carton_Table" ForeColor="#333333"
GridLines="None" AllowSorting="True"
onrowcommand="CartonGridView_RowCommand">