注册 登录
编程论坛 ASP.NET技术论坛

[求助]DataList里放了CheckBox,怎么做全选啊

最毒蜘蛛 发布于 2007-06-12 09:33, 1922 次点击
大家帮帮忙啊!
25 回复
#2
最毒蜘蛛2007-06-12 09:33
大家帮帮忙啊!谢谢了啊!
#3
川流不息2007-06-12 09:34

在上面的貼子我有寫

#4
最毒蜘蛛2007-06-12 09:42
好的,谢谢啊,我去看看去啊!
#5
最毒蜘蛛2007-06-12 09:44
没找到啊,在那个里面呢啊?
#6
最毒蜘蛛2007-06-12 09:55
protected void btnAll_Click(object sender, EventArgs e)
{
if (btnAll.Text == "全选")
{
foreach (GridViewRow row in GvwMaster.Rows) //GridViewRow 要using?
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
cb.Checked = true;
}
btnAll.Text = "全消";
}
else
{
foreach (GridViewRow row in GvwMaster.Rows)
{
CheckBox bc = (CheckBox)row.FindControl("CheckBox1");
bc.Checked = false;
}
btnAll.Text = "全选";
}
}
#7
川流不息2007-06-12 09:59
你把那個全選的貼子全部看完。
#8
最毒蜘蛛2007-06-12 10:35
怎么在DataList里加入CheckBox批量删除记录啊?急急.......
#9
川流不息2007-06-12 10:44
private void btnDEL_Click(object sender, System.EventArgs e)
{
int intCount=0;
for(int i=0;i<this.dgShow.Items.Count;i++)
{
CheckBox chkCB = (CheckBox)dgShow.Items[i].FindControl("chkOPT");
//如果cbk被選中則執行操作
if(chkCB.Checked==true)
{
//得到選中行的第三列的值
string strLandCode = this.dgShow.Items[i].Cells[2].Text.Trim();
strSQL = "DELETE FROM AADA01TB WHERE LandCode='"+strLandCode+"'";
int j = BO.DeleteData(strSQL);//這個方法是自定義的方法,用來刪除數據的,你自己可以寫
if(j>0)
{
intCount++;//得到刪除的數據的數量
}
}
}
if( intCount == dgShow.Items.Count && dgShow.CurrentPageIndex > 0 )
{
//如果刪除數量與當前頁數據總和相等並且當前頁面索引號大於0
//讓DataGrid控件的頁面索號回到前一頁
-- dgShow.CurrentPageIndex;
}
Quary();//操作結束後重新顯示數據,保持數據的更新
}

這是我曾經做過的一個批量刪除,不過是DataGrid,你可以借鑒一下。

[此贴子已经被作者于2007-6-12 10:47:45编辑过]

#10
最毒蜘蛛2007-06-12 11:05
谢谢了啊!
#11
最毒蜘蛛2007-06-12 11:27
private void DataList1_DeleteCommand_1(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{


int tmpCount = this.DataList1.Items.Count;

for (int i = 0 ; i< tmpCount; i++)
{
string tmpID = this.DataList1.DataKeys[i].ToString();

CheckBox delCheckbox =(CheckBox)this.DataList1.Items[i].FindControl("ok");
if (delCheckbox.Checked)
{
conn=new SqlConnection(ConfigurationSettings.AppSettings["sqlConn"]);

conn.Open();
string strSql = "delete from SD_User where id = " + tmpID;
comm= new SqlCommand(strSql,conn);
comm.ExecuteNonQuery();
}
}
//getPic();
this.DataBind();
conn.Close();
}//帮我看看这个那个地方错了啊
#12
最毒蜘蛛2007-06-12 11:29
我跟踪了以下,它根本不走这个事件里过,怎么回事啊,求大家帮帮忙啊!
#13
上炕不脱鞋2007-06-12 11:34
rivate void DataList1_DeleteCommand_1(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)

去掉看看
#14
最毒蜘蛛2007-06-12 11:41
不行啊!还是不走
#15
最毒蜘蛛2007-06-12 11:43
<FooterTemplate>
<asp:Button id="Button2" runat="server" Text="删除分组"></asp:Button>
<asp:Button id="Button3" runat="server" Text="删除好友" CommandName="Delete"></asp:Button>
</FooterTemplate>

我在Button2加CommandName="Delete",结果报下标越界
#16
最毒蜘蛛2007-06-12 11:51
#17
xqyy2007-06-12 11:54

protected

#18
最毒蜘蛛2007-06-12 11:56
private void DataList1_DeleteCommand_1(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{


int tmpCount = this.DataList1.Items.Count;

for (int i = 0 ; i< tmpCount; i++)
{
string tmpID = this.DataList1.DataKeys[i].ToString();

CheckBox delCheckbox =(CheckBox)this.DataList1.Items[i].FindControl("ok");
if (delCheckbox.Checked)
{
conn=new SqlConnection(ConfigurationSettings.AppSettings["sqlConn"]);

conn.Open();
string strSql = "delete from SD_User where id = " + tmpID;
comm= new SqlCommand(strSql,conn);
comm.ExecuteNonQuery();
}
}
//getPic();
this.DataBind();
conn.Close();
}//帮我看看这个那个地方错了啊
#19
最毒蜘蛛2007-06-12 11:56
大家帮我看看啊,我等的都谢了啊!
#20
川流不息2007-06-12 12:05

還是沒有到這個事件中嗎?

#21
最毒蜘蛛2007-06-12 12:21

shi a

#22
最毒蜘蛛2007-06-12 12:22
是啊,还是不到这个事件中啊!
#23
川流不息2007-06-12 13:34
DataList1_DeleteCommand_1把這個事件刪掉,然後再重新雙擊看看跑不跑。
#24
最毒蜘蛛2007-06-12 13:55
DataList1_DeleteCommand,它不报什么错,就是不这个事件不执行,我是北京北大青鸟的
#25
最毒蜘蛛2007-06-12 15:03
好了,我把按纽但写就好了啊!给datagrid的写法是一样的
#26
川流不息2007-06-12 15:06
意思是好了是吧。
1