C# Imagebutton未提供gridview索引,因此无法打开
嗨,我有一个gridview,每一行上都有一个按钮,可以打开一个模式,它可以工作。出于测试目的,我给imagebutton指定了相同的命令名,以查看它是否也会打开模式。不幸的是,它没有 经过一点调试后,我发现imagebutton没有返回行编号的索引,因此当我得到错误时,我的详细信息模式无法显示:C# Imagebutton未提供gridview索引,因此无法打开,c#,jquery,asp.net,gridview,C#,Jquery,Asp.net,Gridview,嗨,我有一个gridview,每一行上都有一个按钮,可以打开一个模式,它可以工作。出于测试目的,我给imagebutton指定了相同的命令名,以查看它是否也会打开模式。不幸的是,它没有 经过一点调试后,我发现imagebutton没有返回行编号的索引,因此当我得到错误时,我的详细信息模式无法显示: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user c
An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code
Additional information: Input string was not in a correct format.
我想知道如何使用imagebutton传递行的索引号
我已将我的代码包括在下面:
加价
<asp:UpdatePanel ID="UserGridViewControl" runat="server">
<ContentTemplate>
<asp:GridView ID="GridViewUsers" runat="server" Width="940px" HorizontalAlign="Center"
OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="false" AllowPaging="true"
DataKeyNames="Ref" CssClass="table table-hover table-striped" OnPageIndexChanging="GridViewUsers_PageIndexChanging"
AllowSorting="true" OnSorting="GridViewUsers_Sorting">
<Columns>
<asp:BoundField DataField="Ref" SortExpression="Ref" HeaderText="Ref #" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Listed" SortExpression="Listed" HeaderText="Listed" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="DateListed" dataformatstring="{0:MMMM d, yyyy}" SortExpression="DateListed" HeaderText="Date Listed" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Type" SortExpression="Type" HeaderText="Type" HeaderStyle-HorizontalAlign="Left" />
<asp:ButtonField CommandName="editRecord" ControlStyle-CssClass="btn btn-info" ButtonType="Button" Text="View Services" HeaderText="Additional Services">
<ControlStyle CssClass="btn btn-info"></ControlStyle>
</asp:ButtonField>
<asp:BoundField DataField="London" SortExpression="London" HeaderText="London" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="MoveInDate" dataformatstring="{0:MMMM d, yyyy}" SortExpression="MoveInDate" HeaderText="Movie in Date" HeaderStyle-HorizontalAlign="Left" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" CommandName="detail" ButtonType="Button" runat="server" />
<asp:ImageButton ID="ImageButton2" runat="server" />
<asp:ImageButton ID="ImageButton3" runat="server" />
<asp:ImageButton ID="ImageButton4" runat="server" />
<asp:ImageButton ID="ImageButton5" runat="server" />
<asp:ImageButton ID="ImageButton6" runat="server" />
<asp:ImageButton ID="ImageButton7" runat="server" />
<asp:ImageButton ID="ImageButton8" runat="server" />
<asp:ImageButton ID="ImageButton9" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="detail" ControlStyle-CssClass="btn btn-info" ButtonType="Button" Text="Detail" HeaderText="Details">
<ControlStyle CssClass="btn btn-info"></ControlStyle>
</asp:ButtonField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
代码隐藏
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("detail"))
{
LoadSortedDB();
int index = Convert.ToInt32(e.CommandArgument); // Breaks Here as there is no value in command argument
Int32 LoweredEmailCheck = Convert.ToInt32(GridViewUsers.DataKeys[index].Value);
IEnumerable<DataRow> query = from i in dt.AsEnumerable()
where i.Field<Int32>("Ref").Equals(LoweredEmailCheck)
select i;
DataTable detailTable = query.CopyToDataTable<DataRow>();
DetailsView1.DataSource = detailTable;
DetailsView1.DataBind();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script type='text/javascript'>");
sb.Append("$('#detailModal').modal('show');");
sb.Append(@"</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "DetailModalScript", sb.ToString(), false);
}
}
使用find获取asp ajax模式弹出窗口的对象
身份证号码:
使用您的代码:
var modalobj=$find("<%=modalid.ClientID%>");
modalobj.show();
var modalobj=$find("Behaviourid");
modalobj.show();
sb.Append(@"<script type='text/javascript'>");
sb.Append("$find('detailModal').show();");
sb.Append(@"</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "DetailModalScript", sb.ToString(), false);