C# 将行索引从GridView中的按钮字段传递到模式弹出窗口
我有一个GridView(见下文),它使用ButtonField按钮启动模式弹出窗口。 这是GridViewC# 将行索引从GridView中的按钮字段传递到模式弹出窗口,c#,asp.net,gridview,modalpopupextender,C#,Asp.net,Gridview,Modalpopupextender,我有一个GridView(见下文),它使用ButtonField按钮启动模式弹出窗口。 这是GridView <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_ButtonClick" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" CssClass="mGrid" AllowPaging="True" PagerStyle-CssCla
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_ButtonClick" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" CssClass="mGrid" AllowPaging="True" PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" OnRowEditing="GridView1_RowEditing" AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="#F7F7F7" CssClass="alt" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<Columns>
<asp:BoundField HeaderText="BeaconID" ShowHeader="True" Visible="True" DataField="beaconObjectid" />
<asp:BoundField DataField="aliasName" HeaderText="My Beacon Name" />
<asp:ButtonField ButtonType="Button" CommandName="AssignName" Text="Assign Name"/>
<asp:BoundField HeaderText="Action Type" DataField="actionType" />
<asp:BoundField DataField="actionContent" HeaderText="Action Content" />
<asp:ButtonField ButtonType="Button" CommandName="AssignAction" Text="Assign/Change Action"/>
</Columns>
<PagerStyle CssClass="pgr" />
</asp:GridView>
问题是当我从我的模式弹出窗口中单击“确定”按钮时。我需要从调用它的gridview按钮字段访问行索引。我的“确定”按钮单击事件如下所示:
protected void setAliasOK_Click(object sender, EventArgs e)
{
var newName = AliasNameTextBox.Text;
ParseChangeAliasName(beaconIDnumber, newName);
SetAliasNameModalPopupExtender.Hide();
}
因此,最终我要问的是,如何将gridview行传递到模式窗口,以便使用来自相应行单元格的数据——在本例中是信标ID(gridview中的DataField=“beaconObjectid”)。
我甚至尝试过在GridView1\u ButtonClick方法中设置全局变量,然后在setAliasOK\u Click方法中引用它们,但是一旦模式窗口打开,它们就会被删除。
理想情况下,如果可能的话,我希望在不使用Javascript的情况下执行此操作。与您得到的方法相同
GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
您可以设置按钮属性:
setAliasOK.CommandName = "AliasOK" ;
setAliasOK.CommandArgument = e.CommandArgument ;
但是您需要处理按钮的RowCommand事件而不是Click事件来获取按钮的命令参数
GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
setAliasOK.CommandName = "AliasOK" ;
setAliasOK.CommandArgument = e.CommandArgument ;