gpt4 book ai didi

c# - ASP.NET Gridview RowUpdating 事件未触发

转载 作者:行者123 更新时间:2023-11-30 22:42:20 27 4
gpt4 key购买 nike

HTML 页面:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView ID="Grd_Threshold" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="Both" AutoGenerateColumns="false" EmptyDataText="No Records." PageSize="8"
AllowPaging="true" OnPageIndexChanging="Grd_Threshold_PageIndexChanging" OnRowCommand="Grd_Threshold_RowCommand"
DataKeyNames="ID" AutoGenerateEditButton="true" OnRowCancelingEdit="Grd_Threshold_RowCancelingEdit" OnRowEditing="Grd_Threshold_RowEditing"
OnRowUpdating="Grd_Threshold_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="No.">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("CLNAME") + ", " + Eval("CFNAME") +" " +Eval("CMNAME")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Doctor" ItemStyle-Width="150px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DOCTORNAME")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Name" ItemStyle-Width="150px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("INAME")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Form" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("IFORM")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Strength" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ISTRG")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Order Date" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ORDERDATE")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price" ItemStyle-Width="80px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("PRICE")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" ItemStyle-Width="80px">
<EditItemTemplate>
<asp:TextBox ID="Txt_Qty" runat="server" Width="50px" Text='<%# Eval("QTY")%>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("QTY")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("USERID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#E3EAEB" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

CS 代码:

 protected void Page_Load(object sender, EventArgs e)
{
try
{
Title = "Dashboard";
if (!Master.Page.IsPostBackEventControlRegistered)
{
BindGrid();
}
}
catch (Exception ex)
{
Common.WriteLog(ex);
}
}

private void BindGrid()
{
try
{
if (SessionUtility.DashboardRecords == null || SessionUtility.DashboardRecords.Rows.Count == 0)
{
string WebServiceUrl = SessionUtility.WebServiceUrl + "/GetAllOrders/";
JsonArrayCollection ReqResponse = Common.GetWebServiceResponse_MultipleValues(WebServiceUrl, "GET");
DataTable Patients = Common.ConvertJsonArrayObjectCollectionToDataTable(ReqResponse);

SessionUtility.DashboardRecords = Patients;
}

if (SessionUtility.UserRight != "1")
{
//Grd_Threshold.Columns[0].Visible = false;
Grd_Threshold.AutoGenerateEditButton = false;
}
else if (SessionUtility.UserRight == "1")
{
Grd_Threshold.AutoGenerateEditButton = true;
}
Grd_Threshold.DataSource = SessionUtility.DashboardRecords;
Grd_Threshold.DataBind();
UpdatePanel1.Update();
}
catch (Exception ex)
{
Common.WriteLog(ex);
}
}

大家好,

在上面编写的代码中,只有 EDIT 事件被触发,并且在 UPDATE、CANCEL 之后只有一次,没有事件被触发。我做错了什么?我只想根据在 QTY 字段中输入的值更改 GridRow 颜色。

最佳答案

我发现了问题。由于我在每一行中为标签提供的 ID 相同,所以事件没有触发。希望这对某人有帮助。

关于c# - ASP.NET Gridview RowUpdating 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4468990/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com