C# 如何在已经有参数的方法中的弹出窗口中显示GridView行?
我试图在已经有参数的方法中的弹出窗口中显示gridview行。我将一个隐藏的ID字段传递到LoadAttorneyPopup方法中,然后我想执行PopulateAttorneyPopup方法,但是当我添加参数来标识GridView时,我需要做什么才能在LoadAttorneyPopup中填充AttorneyPopup使其工作,这样PopulateAttorneyPopup就不会给我“方法没有重载。。。接受0个参数的错误?或者,我是不是找错了方向,有没有其他方法来解决这个问题 以下是GridView:C# 如何在已经有参数的方法中的弹出窗口中显示GridView行?,c#,asp.net,gridview,C#,Asp.net,Gridview,我试图在已经有参数的方法中的弹出窗口中显示gridview行。我将一个隐藏的ID字段传递到LoadAttorneyPopup方法中,然后我想执行PopulateAttorneyPopup方法,但是当我添加参数来标识GridView时,我需要做什么才能在LoadAttorneyPopup中填充AttorneyPopup使其工作,这样PopulateAttorneyPopup就不会给我“方法没有重载。。。接受0个参数的错误?或者,我是不是找错了方向,有没有其他方法来解决这个问题 以下是GridVie
<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>
感谢您的时间和帮助!是的!正如您所演示的,我应该使用参数rowIndex,它非常优雅,现在我看到了它。非常感谢!
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;
}
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;
}