ASP.NET BoundFields 未设置 UpdateParameters
我有一些绑定字段,但它们似乎没有为我的 SQL 语句设置 UpdateParameters。我确实有一些在 SqlDataSource Update 上运行的代码来为非绑定字段设置 UpdateParameters,所以我不确定这是否导致了问题。
我在下面插入了我的代码。
ASP.NET GRIDVIEW
<asp:UpdatePanel ID="reconcileUpdatePanel" runat="server">
<ContentTemplate>
<asp:GridView ID="reconcileGrid" runat="server" AutoGenerateColumns="False"
DataKeyNames="ItemID" DataSourceID="reconcileDataSource" >
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ReadOnly="true" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ReadOnly="true"/>
<asp:BoundField DataField="last_known_location" HeaderText="Last Known Location" SortExpression="last_known_location" ReadOnly="true" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# evalStatus(Eval("Stat")) %>'></asp:Label></ItemTemplate><EditItemTemplate>
<asp:DropDownList ID="ddlReconcileStatus" runat="server" OnSelectedIndexChanged="ddlReconcileStatus_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Value="3" Text="Allocated"></asp:ListItem><asp:ListItem Value="4" Text="Transferred"></asp:ListItem></asp:DropDownList></EditItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Transfer Location">
<EditItemTemplate>
<asp:DropDownList ID="ddlTransferLocation" runat="server"
DataSourceID="ddlTransferLocationDataSource" DataTextField="Name"
DataValueField="ID" Enabled="false" ></asp:DropDownList>
<asp:SqlDataSource
ID="ddlTransferLocationDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name] FROM [TransferLocation]">
</asp:SqlDataSource>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
SQL 数据源
<asp:SqlDataSource ID="reconcileDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
OnUpdating="reconcileGrid_Updating"
SelectCommand="GetReconcileItems" SelectCommandType="StoredProcedure"
UpdateCommand="UpdateReconcileItems" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="ItemID" />
<asp:Parameter Name="TransType" Type="String" />
<asp:Parameter Name="LocationID" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Stat" Type="String" />
<asp:Parameter Name="TransferLocation" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
C# SqlDataSourceUpdating
protected void reconcileGrid_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
DropDownList ddlReconcileStatus = (DropDownList)reconcileGrid.Rows[reconcileGrid.EditIndex].Cells[0].FindControl("ddlReconcileStatus");
DropDownList ddlTransferLocation = (DropDownList)reconcileGrid.Rows[reconcileGrid.EditIndex].Cells[0].FindControl("ddlTransferLocation");
// Set the Stat Value
reconcileDataSource.UpdateParameters["Stat"].DefaultValue = ddlReconcileStatus.SelectedValue.ToString();
//Test to see if the value needs to be set or not
if (ddlReconcileStatus.SelectedValue == "4")
reconcileDataSource.UpdateParameters["TransferLocation"].DefaultValue = ddlTransferLocation.SelectedValue.ToString();
if (ddlReconcileStatus.SelectedValue == "3")
reconcileDataSource.UpdateParameters["TransferLocation"].DefaultValue = null;
string test1 = reconcileDataSource.UpdateParameters["LocationID"].DefaultValue.ToString();
}
I have a few bound fields, but they don't seem to be setting the UpdateParameters for my SQL statement. I do have some code that runs on SqlDataSource Update to set UpdateParameters for non bound fields, so I'm not sure if that is causing the problem.
I've inserted my code below.
ASP.NET GRIDVIEW
<asp:UpdatePanel ID="reconcileUpdatePanel" runat="server">
<ContentTemplate>
<asp:GridView ID="reconcileGrid" runat="server" AutoGenerateColumns="False"
DataKeyNames="ItemID" DataSourceID="reconcileDataSource" >
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ReadOnly="true" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ReadOnly="true"/>
<asp:BoundField DataField="last_known_location" HeaderText="Last Known Location" SortExpression="last_known_location" ReadOnly="true" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# evalStatus(Eval("Stat")) %>'></asp:Label></ItemTemplate><EditItemTemplate>
<asp:DropDownList ID="ddlReconcileStatus" runat="server" OnSelectedIndexChanged="ddlReconcileStatus_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Value="3" Text="Allocated"></asp:ListItem><asp:ListItem Value="4" Text="Transferred"></asp:ListItem></asp:DropDownList></EditItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Transfer Location">
<EditItemTemplate>
<asp:DropDownList ID="ddlTransferLocation" runat="server"
DataSourceID="ddlTransferLocationDataSource" DataTextField="Name"
DataValueField="ID" Enabled="false" ></asp:DropDownList>
<asp:SqlDataSource
ID="ddlTransferLocationDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name] FROM [TransferLocation]">
</asp:SqlDataSource>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
SQL DATA SOURCE
<asp:SqlDataSource ID="reconcileDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
OnUpdating="reconcileGrid_Updating"
SelectCommand="GetReconcileItems" SelectCommandType="StoredProcedure"
UpdateCommand="UpdateReconcileItems" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="ItemID" />
<asp:Parameter Name="TransType" Type="String" />
<asp:Parameter Name="LocationID" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Stat" Type="String" />
<asp:Parameter Name="TransferLocation" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
C# SqlDataSourceUpdating
protected void reconcileGrid_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
DropDownList ddlReconcileStatus = (DropDownList)reconcileGrid.Rows[reconcileGrid.EditIndex].Cells[0].FindControl("ddlReconcileStatus");
DropDownList ddlTransferLocation = (DropDownList)reconcileGrid.Rows[reconcileGrid.EditIndex].Cells[0].FindControl("ddlTransferLocation");
// Set the Stat Value
reconcileDataSource.UpdateParameters["Stat"].DefaultValue = ddlReconcileStatus.SelectedValue.ToString();
//Test to see if the value needs to be set or not
if (ddlReconcileStatus.SelectedValue == "4")
reconcileDataSource.UpdateParameters["TransferLocation"].DefaultValue = ddlTransferLocation.SelectedValue.ToString();
if (ddlReconcileStatus.SelectedValue == "3")
reconcileDataSource.UpdateParameters["TransferLocation"].DefaultValue = null;
string test1 = reconcileDataSource.UpdateParameters["LocationID"].DefaultValue.ToString();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论