u012370894
沉默之剑TAO
采纳率0%
2017-12-19 08:54 阅读 1.1k

.net 使用gridview+bootstrap模态框

5

.net 使用gridview+bootstrap模态框,怎样取gridview某列值放在模态框的input里

html代码:

 <asp:TemplateField HeaderText="操作">
                    <ItemTemplate>
                        <asp:Button runat="server" ID="edit" CommandArgument="<%# Container.DataItemIndex+1 %>" Text="Edit" CommandName="editLoc" CssClass="btn btn-primary" data-toggle="modal" data-target="#myModal" />
                    </ItemTemplate>
                </asp:TemplateField>


模态框响应;
function getGridViewValue(con_id, con_name, current_loc) {
$('#myModal').on('shown.bs.modal', function () {
$("#con_edit_id").val(con_id);
$("#con_edit_name").val(con_name);
$("#current_edit_loc").val(current_loc);
});

    }

后台代码:
 protected void gvin_RowCommand(object sender,GridViewCommandEventArgs e)
    {

        if (e.CommandName=="editLoc")
        {
            int index = Convert.ToInt32(e.CommandArgument.ToString());
            Button btn = (Button)gvin.Rows[index].FindControl("edit");
            btn.Attributes.Add("onclick", "getGridViewValue('" + gvin.Rows[index].Cells[0].Text + "','" + gvin.Rows[index].Cells[1].Text + "','" + gvin.Rows[index].Cells[2].Text + "')");
        }

    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐