如何在已经有参数的方法中弹出显示GridView行
本文关键字:显示 GridView 方法 参数 | 更新日期: 2023-09-27 17:49:58
我试图在一个已经有参数的方法中显示gridview行。我正在传递一个隐藏的ID字段到LoadAttorneyPopup方法,然后我想执行PopulateAttorneyPopup方法,但是当我添加参数来识别GridView时,我要对LoadAttorneyPopup中的PopulateAttorneyPopup做些什么来使它工作,所以PopulateAttorneyPopup不会给我"No overload for method…接受0个参数"错误?或者,我是找错对象了,有没有别的方法可以解决这个问题?
这是GridView:
<asp:GridView ID="gvAttorneys" runat="server" HeaderStyle-Font-Size="X-small"
AutoGenerateColumns = "false" AlternatingRowStyle-BackColor = "LightGray"
HeaderStyle-BackColor = "#7ac0da" HeaderStyle-ForeColor="Black" OnRowDeleting="gvAttorneys_RowDeleting" OnRowCommand="gvAttorneys_RowCommand">
<Columns>
<asp:TemplateField HeaderStyle-Font-Size="Small" HeaderText="">
<ItemTemplate>
<asp:HiddenField ID="hdAttorneyID" runat="server" Value='<%#Bind("attorneyID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="attorneyName" HeaderText="Name of Attorney" ItemStyle-CssClass="alpsGrid" HeaderStyle-Font-Size="Small" ItemStyle-Width="300px" SortExpression="attorneyName" />
<asp:BoundField DataField="startDate" HeaderText="Firm Start Date" ControlStyle-Width="150px" ItemStyle-Width="150px" HeaderStyle-Font-Size="Small" DataFormatString="{0:d}"/>
<asp:BoundField DataField="cleCredit" HeaderText="Completed 3+ Hours of CLE" ControlStyle-Width="150px" HeaderStyle-Font-Size="Small"/>
<asp:BoundField DataField="last4SS" HeaderText="Last 4 of S.S.#" ControlStyle-Width="150px" HeaderStyle-Font-Size="Small" ItemStyle-Width="300px"/>
<asp:TemplateField ItemStyle-Width = "30px">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="EditAttorney" Text = "Edit" CommandArgument='<%# Container.DataItemIndex %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width = "30px">
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete" Text = "Delete" OnClientClick="return confirm('This will permanently remove this record: Continue?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
下面是后面的代码:
protected void gvAttorneys_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditAttorney")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvAttorneys.Rows[index];
HiddenField hdAttorneyID = row.FindControl("hdAttorneyID") as HiddenField;
string attorneyID = hdAttorneyID.Value;
int intAttorneyID = 0;
if (int.TryParse(attorneyID, out intAttorneyID))
{
LoadAttorneyPopup(intAttorneyID);
}
}
}
private void LoadAttorneyPopup(int intAttorneyID)
{
ResetAttorneyPopup();
hdAttorneyID_Popup.Value = intAttorneyID.ToString();
if (intAttorneyID > 0)
{
PopulateAttorneyPopup();
}
popup.Show();
}
private void PopulateAttorneyPopup(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = gvAttorneys.Rows[Convert.ToInt32(e.CommandArgument)];
txtAttorneyName.Text = row.Cells[0].Text;
txtStartDate.Text = row.Cells[1].Text;
cblCLECompleted.Text = row.Cells[2].Text;
txtLast4ofSS.Text = row.Cells[3].Text;
}
感谢您的时间和帮助!
protected void gvAttorneys_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditAttorney")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvAttorneys.Rows[index];
HiddenField hdAttorneyID = row.FindControl("hdAttorneyID") as HiddenField;
string attorneyID = hdAttorneyID.Value;
int intAttorneyID = 0;
if (int.TryParse(attorneyID, out intAttorneyID))
{
LoadAttorneyPopup(intAttorneyID,index);
}
}
}
private void LoadAttorneyPopup(int intAttorneyID,int rowIndex)
{
ResetAttorneyPopup();
hdAttorneyID_Popup.Value = intAttorneyID.ToString();
if (intAttorneyID > 0)
{
PopulateAttorneyPopup(rowIndex);
}
popup.Show();
}
private void PopulateAttorneyPopup(int rowIndex)
{
GridViewRow row = gvAttorneys.Rows[rowIndex];
txtAttorneyName.Text = row.Cells[0].Text;
txtStartDate.Text = row.Cells[1].Text;
cblCLECompleted.Text = row.Cells[2].Text;
txtLast4ofSS.Text = row.Cells[3].Text;
}