标题:javascript判断GRIDVIEW问题
只看楼主
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
 问题点数:0 回复次数:9 
javascript判断GRIDVIEW问题
我想用javascript判断我选中的行是否删除 但是我点否它也能删除 为什么?
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[6].Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
}
搜索更多相关主题的帖子: javascript GRIDVIEW Row 判断 Add 
2007-03-05 09:40
summoner
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1622
专家分:0
注 册:2005-3-3
得分:0 
Cells[6]里是放的什么控件?button吗?
试试这样
(Button(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");

[URL=javascript:window.close();e=new Enumerator(window.opener.document.images);for(;!e.atEnd();e.moveNext()){e.item().src=\'http://blog./UploadFiles/2007-1/117175967.gif\';}]其疾如風、其徐如林、侵掠如火、不動如山、難知如陰、動如雷震[/URL]
2007-03-05 10:12
cyyu_ryh
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:1899
专家分:176
注 册:2006-10-21
得分:0 
#region 删除提示
protected void gv_Message_RowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButton btn_del = (LinkButton)(e.Row.FindControl("LinkButton1"));
if (btn_del != null)
{
btn_del.Attributes.Add("onClick", "javascript:return confirm('你确定要删除吗?');");
}
}
#endregion

有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@
2007-03-05 12:36
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
楼上正解,写在..DataBound()里面

飘过~~
2007-03-05 12:40
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
得分:0 

你这样没提示
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Xhhy.MSSQLClass;
using System.Data.SqlClient;
using Xhhy.Function;
using Xhhy.TbClass;
public partial class tieba_mg_Tbapplicamg : System.Web.UI.Page
{
int Certifi;
protected void Page_Load(object sender, EventArgs e)
{
// CheckLogin.isAdminLogin(Request, "/manage/MainLogin.aspx", Response);
System.Text.StringBuilder scriptString = new System.Text.StringBuilder();

scriptString.Append("<script language=JavaScript> ");

scriptString.Append("function DelConfirm() {");

scriptString.Append("return confirm('确认批量删除所选择的吗?');}");

scriptString.Append("</script>");

String js = scriptString.ToString();

if (!IsClientScriptBlockRegistered("DelConfirm"))
{
RegisterClientScriptBlock("DelConfirm", js);
}
this.cmdpiliang.Attributes.Add("onclick", "return DelConfirm()");
}
protected string QqjyTbmaster()
{
string sqlsr = "";
if (TxtTbMasterID.Text.Trim() != "")
{
sqlsr = "SELECT QqjyTbMasters.MastersID, QqjyTbBroad.BroadName, QqjyTbMasters.MastersName, QqjyTbMasters.MastersTime,QqjyTbMasters.Certification FROM QqjyTbMasters INNER JOIN QqjyTbBroad ON QqjyTbMasters.BroadId = QqjyTbBroad.BroadId where MastersID like '%" + this.TxtTbMasterID.Text.Trim() + "%'";
if (TxtTbBroadName.Text.Trim() != "")
sqlsr += " and BroadName like '%" + TxtTbBroadName.Text.Trim() + "%'";
if (TxtTbMasters.Text.Trim() != "")
sqlsr += " and MastersName like '%" + TxtTbMasters.Text.Trim() + "%'";
if (ddlTbCertifi.Text.Trim() != "")
{
if (ddlTbCertifi.SelectedItem.Text.Trim() != "未验证")
{
sqlsr += "and QqjyTbMasters.Certification ='1'";
}
else
{
sqlsr += "and QqjyTbMasters.Certification ='0'";
}

}

if (this.kaishishijian.Value != "" && this.jiesushijian.Value != "")
{
string kaishi = this.kaishishijian.Value.Trim().ToString();
string jieshu = this.jiesushijian.Value.Trim().ToString();
sqlsr += "and MastersTime BETWEEN '" + kaishi + "' and '" + jieshu + "' ";
}
}
else if (TxtTbBroadName.Text.Trim() != "")
{
sqlsr = "SELECT QqjyTbMasters.MastersID,QqjyTbBroad.BroadName, QqjyTbMasters.MastersName,QqjyTbMasters.MastersTime,QqjyTbMasters.Certification FROM QqjyTbMasters INNER JOIN QqjyTbBroad ON QqjyTbMasters.BroadId = QqjyTbBroad.BroadId where BroadName like '%" + this.TxtTbBroadName.Text.Trim() + "%'";
if (TxtTbMasters.Text.Trim() != "")
sqlsr += " and MastersName like '%" + TxtTbMasters.Text.Trim() + "%'";
if (ddlTbCertifi.Text.Trim() != "")
{
if (ddlTbCertifi.SelectedItem.Text.Trim() != "未验证")
{
sqlsr += "and QqjyTbMasters.Certification ='1'";
}
else
{
sqlsr += "and QqjyTbMasters.Certification ='0'";
}

}


if (this.kaishishijian.Value != "" && this.jiesushijian.Value != "")
{
string kaishi = this.kaishishijian.Value.Trim().ToString();
string jieshu = this.jiesushijian.Value.Trim().ToString();
sqlsr += "and MastersTime BETWEEN '" + kaishi + "' and '" + jieshu + "' ";
}
}
else if (TxtTbMasters.Text.Trim() != "")
{
sqlsr = "SELECT QqjyTbMasters.MastersID, QqjyTbBroad.BroadName, QqjyTbMasters.MastersName, QqjyTbMasters.MastersTime,QqjyTbMasters.Certification FROM QqjyTbMasters INNER JOIN QqjyTbBroad ON QqjyTbMasters.BroadId = QqjyTbBroad.BroadId where MastersName like '%" + this.TxtTbMasters.Text.Trim() + "%'";
if (ddlTbCertifi.Text.Trim() != "")
{
if (ddlTbCertifi.SelectedItem.Text.Trim() != "未验证")
{
sqlsr += "and QqjyTbMasters.Certification ='1'";
}
else
{
sqlsr += "and QqjyTbMasters.Certification ='0'";
}

}

if (this.kaishishijian.Value.Trim() != "" && this.jiesushijian.Value.Trim() != "")
{
string kaishi = this.kaishishijian.Value.Trim().ToString();
string jieshu = this.jiesushijian.Value.Trim().ToString();
sqlsr += "and MastersTime BETWEEN '" + kaishi + "' and '" + jieshu + "' ";
}
}
else if (ddlTbCertifi.Text.Trim() != "")
{
if (ddlTbCertifi.SelectedItem.Text.Trim() != "未验证")
{
sqlsr = "SELECT QqjyTbMasters.MastersID, QqjyTbBroad.BroadName, QqjyTbMasters.MastersName, QqjyTbMasters.MastersTime,QqjyTbMasters.Certification FROM QqjyTbMasters INNER JOIN QqjyTbBroad ON QqjyTbMasters.BroadId = QqjyTbBroad.BroadId where QqjyTbMasters.Certification='1'";
}
else
{
sqlsr = "SELECT QqjyTbMasters.MastersID, QqjyTbBroad.BroadName, QqjyTbMasters.MastersName, QqjyTbMasters.MastersTime,QqjyTbMasters.Certification FROM QqjyTbMasters INNER JOIN QqjyTbBroad ON QqjyTbMasters.BroadId = QqjyTbBroad.BroadId where QqjyTbMasters.Certification='0'";
}
if (this.kaishishijian.Value != "" && this.jiesushijian.Value != "")
{
string kaishi = this.kaishishijian.Value.Trim().ToString();
string jieshu = this.jiesushijian.Value.Trim().ToString();
sqlsr += "and MastersTime BETWEEN '" + kaishi + "' and '" + jieshu + "' ";
}
}
else if (this.kaishishijian.Value != "" && this.jiesushijian.Value != "")
{
string kaishi = this.kaishishijian.Value.Trim().ToString();
string jieshu = this.jiesushijian.Value.Trim().ToString();
sqlsr = "SELECT QqjyTbMasters.MastersID, QqjyTbBroad.BroadName, QqjyTbMasters.MastersName, QqjyTbMasters.MastersTime,QqjyTbMasters.Certification FROM QqjyTbMasters INNER JOIN QqjyTbBroad ON QqjyTbMasters.BroadId = QqjyTbBroad.BroadId where MastersTime BETWEEN '" + kaishi + "' and '" + jieshu + "'";
}
else
{
sqlsr = "SELECT QqjyTbMasters.MastersID, QqjyTbBroad.BroadName, QqjyTbMasters.MastersName, QqjyTbMasters.MastersTime,QqjyTbMasters.Certification FROM QqjyTbMasters INNER JOIN QqjyTbBroad ON QqjyTbMasters.BroadId = QqjyTbBroad.BroadId";
}
this.SqlDataSource1.SelectCommand = sqlsr;
return sqlsr;
}
protected void BbtnSearch_Click(object sender, EventArgs e)
{
this.QqjyTbmaster();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[6].Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
}

}

protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
((CheckBox)row.Cells[0].FindControl("xxx")).Checked = true;
}
}
protected void cmdpiliang_Click1(object sender, EventArgs e)
{
for (int row = 0; row < this.GridView1.Rows.Count; row++)
{
if (((CheckBox)this.GridView1.Rows[row].Cells[0].FindControl("xxx")).Checked == true)
{
int id = Convert.ToInt32(this.GridView1.DataKeys[row].Value);
string sqlstr = "delete from QqjyTbMasters where MastersID = " + id;
Database.ExecuteSql(sqlstr);
}
}
this.GridView1.DataBind();
}
protected void cmdquxiao_Click1(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
((CheckBox)row.Cells[0].FindControl("xxx")).Checked = false;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
string sqlsr = this.QqjyTbmaster();
SqlDataSource1.SelectCommand = sqlsr;
}
}


我的全部代码是这样的 红色的代码是我用来判断的

2007-03-05 13:55
cyyu_ryh
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:1899
专家分:176
注 册:2006-10-21
得分:0 
有啊
不然就把该列设置为模板列,但觉得没有必要。
2楼的不是告诉你的错误了吗?
为什么不改呢?

有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@
2007-03-05 14:35
梦的守护神
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2006-5-25
得分:0 

那种方法不行

2007-03-05 15:18
cyyu_ryh
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:1899
专家分:176
注 册:2006-10-21
得分:0 
我自己就是这样做的啊
可以提示的

有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@
2007-03-05 15:37
ivory_tt
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2006-3-1
得分:0 
以下是引用cyyu_ryh在2007-3-5 15:37:30的发言:
我自己就是这样做的啊
可以提示的


2007-03-05 16:43
ivory_tt
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2006-3-1
得分:0 
以下是引用ivory_tt在2007-3-5 16:43:40的发言:


2007-03-05 16:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-122540-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023651 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved