嗨我有一个gridview,每行都有一个按钮,打开一个模态,它可以工作。出于测试目的,我给了我的imagebutton相同的commandName,看它是否也会打开模态。不幸的是它没有......
经过一些调试后我发现imagebutton没有返回索引(行号)所以我的详细模式无法显示,因为我收到错误:
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);
}
}
答案 0 :(得分:0)
使用find
获取asp ajax模态弹出窗口的对象
,ID为
var modalobj=$find("<%=modalid.ClientID%>");
modalobj.show();
与Behaviourid:
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);