gpt4 book ai didi

javascript - 使用 RowCommand 事件在 GridView 上编辑单击弹出 Bootstrap 模型

转载 作者:可可西里 更新时间:2023-11-01 02:24:47 24 4
gpt4 key购买 nike

我有一个 Bootstrap 模型弹出窗口:

<asp:UpdatePanel ID="upModal" runat="server">
<ContentTemplate>

<!-- Bootstrap Modal Dialog -->
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">ADD NEW BANQUET</h4>
</div>
<div class="modal-body" style="padding-left: 0px;padding-right:0px">
<div class="col-lg-12" style="padding-left: 0px;padding-right:0px">
<div class="form-group col-lg-6">
<label>Banquet ID:</label>
<u><asp:Label ID="lblID" CssClass="form-control" Text="AUTO ID" runat="server"></asp:Label></u>
</div>
<div class="form-group col-lg-6">
<label>Banquet Name:</label>
<asp:TextBox ID="txtName" CssClass="form-control" runat="server"></asp:TextBox>
</div>
</div>

<div class="modal-footer" style="padding-left: 0px;padding-right:0px">
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click"
CssClass="btn btn-success btn-lg btn-block" Text="SAVE" UseSubmitBehavior="false"
data-dismiss="modal" />
</div>
</div>
</div>
</div>
</div>
<!-- /.modal -->

</ContentTemplate>
</asp:UpdatePanel>
<!-- /.upModel -->

而 GridView 是:

<div class="col-lg-12 table-responsive">
<asp:GridView ID="gvBanquet" CssClass="table table-striped table-bordered table-hover" runat="server"
AutoGenerateColumns="false" OnRowCommand="gvBanquet_RowCommand" AllowPaging="True" PageSize="5"
EmptyDataText="No record found!" OnPageIndexChanging="gvBanquet_PageIndexChanging" ShowHeaderWhenEmpty="true">
<Columns>
<asp:TemplateField HeaderText="Banquet Name">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Visible="false" Text='<% #Eval("bqtID") %>'></asp:Label>
<asp:Label ID="lblName" runat="server" Text='<% #Eval("bqtName") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
<HeaderTemplate>
<center>Events</center>
</HeaderTemplate>
<ItemTemplate>
<asp:Button ID="btnEdiit" runat="server" CssClass="btn btn-danger btn-sm" CommandName="EditRow" Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#5cb85c" BorderColor="#4CAE4C" ForeColor="White"></HeaderStyle>
<PagerStyle Font-Size="Larger" ForeColor="Black" HorizontalAlign="Center" />
</asp:GridView>
</div>
<!-- /.col-lg-12 -->

这是 RowCommand 事件:

protected void gvBanquet_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
int index = row.RowIndex;

string id = GetTextFromGridViewLabel(gvBanquet,index,"lblID");
string name = GetTextFromGridViewLabel(gvBanquet, index, "lblName");

switch (e.CommandName)
{
case "EditRow":
lblID.Text = id;
txtName.Text = name;
break;
default:
break;
}
}

我的问题是,当我在 GridView 中单击“编辑”按钮时,引导模型不会弹出 GridView 行中的 idname

最佳答案

这里可以是一个解决方案并按照以下步骤操作:

  • 也在另一个 UpdatePanel 中添加 GridView。
  • 在第一个 UpdatePanel upModel 中触发 GridView RowCommand 事件,如下所示:

    <ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="gvBanquet" EventName="RowCommand" />
    </Triggers>
  • 最后在 RowCommand 事件中运行 StringBuilder 代码:

    case "EditRow":
    lblID.Text = id;
    txtName.Text = name;

    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(@"<script type='text/javascript'>");
    sb.Append("$('#myModal').modal('show');");
    sb.Append(@"</script>");
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "MyModal",
    sb.ToString(), false);

    break;

它将在编辑点击时显示弹出窗口:

enter image description here

关于javascript - 使用 RowCommand 事件在 GridView 上编辑单击弹出 Bootstrap 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46409549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com