.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 + "')");
}
}