gridview在行中添加单击事件后,如何去除其中一列 10
在GridView中,在每一行中添加了单击事件,用于弹出模式对话框,第一列是CheckBox,如何选中CheckBox而不触发单击事件?可以这样加OnClick事件:e....
在GridView中,在每一行中添加了单击事件,用于弹出模式对话框,第一列是CheckBox,如何选中CheckBox而不触发单击事件?
可以这样加OnClick事件:
e.Row.Cells[i].Attributes.Add("onclick", "ScanSendMessageDetail('" + messageId + "','send')"); 展开
可以这样加OnClick事件:
e.Row.Cells[i].Attributes.Add("onclick", "ScanSendMessageDetail('" + messageId + "','send')"); 展开
展开全部
实例:
<asp:GridView 中用到的复选框,多选,全选,批量删除数据
前台页面:
<script type="text/javascript">
function GetAllCheckBox(parentItem) {
var items = document.getElementsByTagName("input");
for (i = 0; i < items.length; i++) {
if (parentItem.checked) {
if (items[i].type == "checkbox") {
items[i].checked = true;
}
}
else {
if (items[i].type == "checkbox") {
items[i].checked = false;
}
}
}
}
</script>
<asp:GridView ID="gvwColumnList" runat="server" AutoGenerateColumns="false" DataKeyNames="id" OnRowDeleting="gvwColumnListRowDeleting">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="selectall" onclick="GetAllCheckBox(this);" />
</HeaderTemplate>
<ItemTemplate>
<div align="center"><input type="checkbox" runat="server" id="cbxContact" /></div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="ColumnName" HeaderText="栏目名" />
<asp:BoundField DataField="WebUrl" HeaderText="WebUrl" />
<asp:BoundField DataField="State" HeaderText="状态" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="true"/>
</Columns>
</asp:GridView>
c#:
//获取批量删除的Id(Ids) 这里就是获取当前行的ID了
public string gvwCustomListDelByIds()
{
System.Text.StringBuilder columnIds = new System.Text.StringBuilder();
for (int i = 0; i <= gvwColumnList.Rows.Count - 1; i++)
{
System.Web.UI.HtmlControls.HtmlInputCheckBox cbx = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwColumnList.Rows[i].FindControl("cbxContact");
if (cbx.Checked)
{
columnIds.Append(gvwColumnList.DataKeys[i].Value.ToString() + ",");
}
}
return columnIds.ToString().Trim(',');
}
//确认批量删除
protected void btnDel_Click(object sender, EventArgs e)
{
if (columnbll.ColumnDel(gvwCustomListDelByIds()))
{
Response.Write("<script>alert('删除成功')</script>");
}
else
{
Response.Write("<script>alert('删除失败')</script>");
}
bind();
}
<asp:GridView 中用到的复选框,多选,全选,批量删除数据
前台页面:
<script type="text/javascript">
function GetAllCheckBox(parentItem) {
var items = document.getElementsByTagName("input");
for (i = 0; i < items.length; i++) {
if (parentItem.checked) {
if (items[i].type == "checkbox") {
items[i].checked = true;
}
}
else {
if (items[i].type == "checkbox") {
items[i].checked = false;
}
}
}
}
</script>
<asp:GridView ID="gvwColumnList" runat="server" AutoGenerateColumns="false" DataKeyNames="id" OnRowDeleting="gvwColumnListRowDeleting">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="selectall" onclick="GetAllCheckBox(this);" />
</HeaderTemplate>
<ItemTemplate>
<div align="center"><input type="checkbox" runat="server" id="cbxContact" /></div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="ColumnName" HeaderText="栏目名" />
<asp:BoundField DataField="WebUrl" HeaderText="WebUrl" />
<asp:BoundField DataField="State" HeaderText="状态" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="true"/>
</Columns>
</asp:GridView>
c#:
//获取批量删除的Id(Ids) 这里就是获取当前行的ID了
public string gvwCustomListDelByIds()
{
System.Text.StringBuilder columnIds = new System.Text.StringBuilder();
for (int i = 0; i <= gvwColumnList.Rows.Count - 1; i++)
{
System.Web.UI.HtmlControls.HtmlInputCheckBox cbx = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwColumnList.Rows[i].FindControl("cbxContact");
if (cbx.Checked)
{
columnIds.Append(gvwColumnList.DataKeys[i].Value.ToString() + ",");
}
}
return columnIds.ToString().Trim(',');
}
//确认批量删除
protected void btnDel_Click(object sender, EventArgs e)
{
if (columnbll.ColumnDel(gvwCustomListDelByIds()))
{
Response.Write("<script>alert('删除成功')</script>");
}
else
{
Response.Write("<script>alert('删除失败')</script>");
}
bind();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询