我使用GridView
来显示要由用户验证的错误信息。然后,为用户提供可填写字段(datepicker
,dropdownlist
,textbox
)以修复错误。这些都在GridView
之外。
之后,他们有一个提交按钮,用于将更改保存到SQL日志中。我遇到的问题是,因为我正在传递object sender, GridViewRowEventsArg e
,按钮无法识别GridView
而我收到错误:
No overload for 'btnSaveMemberErrorEdit_ButtonClicked' matches delegate 'System.EventHandler'
我正在使用带有c#代码的asp.net
。示例代码为:
ASP:
<div id="actionItemAccordion">
<h3>Action Items</h3>
<asp:Panel runat="server">
<asp:GridView runat="server" ID="gridActionItems" DataKeyNames="ErrorKey"
AutoGenerateColumns="false" EmptyDataText="No Action Items Were Found." ShowHeader="true"
ClientIDMode="Static" Width="100%">
<Columns>
<asp:BoundField HeaderText="Action Item" DataField="ActionItem" />
<asp:BoundField HeaderText="Month" DataField="Month" />
<asp:BoundField HeaderText="Data" DataField="DCode" />
<asp:BoundField HeaderText="Data2" DataField="D2Code" />
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList runat="server" ID="rbWinner" AutoPostBack="true" Font-Size="Smaller" >
<asp:ListItem Text="D1 Correct" Enabled="true" Value="D1" />
<asp:ListItem Text="D2 Correct" Enabled="true" Value="D2" />
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label runat="server" BorderWidth="2px" Width="850px"></asp:Label>
<div>
<asp:Label runat="server" Text="Edit Any Necessary Changes" Style="text-align: center"
Font-Size="Medium" Visible="true" Font-Bold="true" Width="100%" />
<br />
<br />
</div>
<div>
<asp:Label runat="server" Text="Effective Date: " Style="text-align: right"
Font-Size="Small" Visible="true" Width="200px" />
<asp:TextBox runat="server" ID="txtEffectiveDate" Text="" Style="text-align: left"
ClientIDMode="Static" Font-Size="13px" Columns="15" Height="15" Width="15%" />
<asp:Label runat="server" Text="Termination Date: " Style="text-align: right"
Font-Size="Small" Visible="true" Width="200px" />
<asp:TextBox runat="server" ID="txtTerminationDate" Text="" Style="text-align: left"
ClientIDMode="Static" Font-Size="13px" Columns="15" Height="15" Width="15%" />
<br />
<br />
</div>
<div>
<asp:Label runat="server" Text="New/Corrected Name: " Style="text-align: right"
Font-Size="Small" Visible="true" Width="200px" />
<asp:DropDownList runat="server" ID="ddlNewCode" AutoPostBack="false" AppendDataBoundItems="true"
Style="text-align: left" Width="220" BackColor="AliceBlue" ClientIDMode="Static"
DataTextField="Code" DataValueField="CodeKey">
</asp:DropDownList>
<br />
<br />
<asp:Label runat="server" BorderWidth="1px" Width="850px"></asp:Label>
<br />
</div>
<div>
<asp:Label runat="server" Text="Notes: " Style="text-align: right; vertical-align: middle"
Font-Size="Small" Visible="true" Width="200px" />
<asp:TextBox runat="server" ID="txtNotes" Text="" Style="text-align: left" ClientIDMode="Static"
Wrap="true" TextMode="MultiLine" Font-Size="10px" Columns="100" Height="100"
Width="50%" />
</div>
<div>
<asp:Button runat="server" ID="btnSaveErrorEdit" Text="Save Changes" OnClick="btnSaveErrorEdit_ButtonClicked"
Height="30px" Enabled="true" Width="95px" Style="margin-left: 330px; margin-top: 70px;
margin-bottom: 25px; padding: 0px; border-radius: 5px;" />
<asp:Button runat="server" ID="btnCancelEdit" Text="Cancel" OnClientClick="return CancelEdit();"
Enabled="true" Height="30px" Width="70px" Style="margin-right: 330px; margin-top: 70px;
margin-bottom: 25px; padding: 0px; border-radius: 5px;" />
</div>
</asp:Panel>
代码背后:
protected void btnSaveErrorEdit_ButtonClicked(object sender, GridViewRowEventArgs e)
{
int hiddenErrorKey = Convert.ToInt32(e.Row.Cells[5].Text);
this.assignCorrect = e.Row.Cells[4].Text;
SqlCommand command = new SqlCommand("some_storedProc");
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@ErrorKey", SqlDbType.Int).Value = hiddenErrorKey;
command.Parameters.Add("@EffectiveDate", SqlDbType.DateTime).Value = this.txtEffectiveDate;
command.Parameters.Add("@TerminationDate", SqlDbType.DateTime).Value = this.txtTerminationDate;
command.Parameters.Add("@Notes", SqlDbType.VarChar, -1).Value = this.txtNotes;
command.Parameters.Add("@NameOfInputUser", SqlDbType.VarChar, 50).Value = this.lblInputUserName;
command.Parameters.Add("@Code", SqlDbType.VarChar, 1).Value = this.assignWinner;
Utilities.Exec_Qry(this.Application["some_connection"].ToString(), command);
}
答案 0 :(得分:1)
您需要更改函数以获取asp:button
的参数(object sender, EventArgs e)
然后你可以使用
在后面的代码中获取GridViewvar button = sender as Button;
var view = button.FindControl("gridActionItems") as GridView;
然后您可以根据需要访问元素。