datalist中使用linkbutton传递参数查询
1个回答
2011-05-27
展开全部
在属性里 先设置文本字段(id), URL字段 (id),再设URL格式字符串
格式例如:Bed xiugai.aspx?id={0}
给你个例子你参考一下吧!
在.CS文件下填加下面的代码:
SqlCommand cmd, cmd1, cmd2;
SqlConnection cn;
SqlDataReader dr, dr1;
SqlDataAdapter da, da1;
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();private void databindlist()
{
cn = sqldata.createcon();
cn.Open();
strsql = "select * from Bed";
da = new SqlDataAdapter(strsql, cn);
da.Fill(ds, "id");
this.mydatagrid.DataKeyField = "id";
this.mydatagrid.DataSource = ds.Tables["id"].DefaultView;
this.mydatagrid.DataBind();
}
protected void mydatagrid_DeleteCommand(object source, DataGridCommandEventArgs e)
{
int id = Convert.ToInt32(this.mydatagrid.DataKeys[e.Item.ItemIndex].ToString());
cn = sqldata.createcon();
cn.Open();
strsql1 = "delete from Bed where id=" +id;
cmd1 = new SqlCommand(strsql1, cn);
cmd1.ExecuteNonQuery();
this.databindlist();
this.lbltishi.Text = "删除成功";
}
protected void mydatagrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#d3d3d3'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
((LinkButton)(e.Item.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('您确认要删除吗?');");
}
}
protected void mydatagrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.mydatagrid.CurrentPageIndex = e.NewPageIndex;
this.databindlist();
}
不知道对你有没有用 你看一下吧!
格式例如:Bed xiugai.aspx?id={0}
给你个例子你参考一下吧!
在.CS文件下填加下面的代码:
SqlCommand cmd, cmd1, cmd2;
SqlConnection cn;
SqlDataReader dr, dr1;
SqlDataAdapter da, da1;
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();private void databindlist()
{
cn = sqldata.createcon();
cn.Open();
strsql = "select * from Bed";
da = new SqlDataAdapter(strsql, cn);
da.Fill(ds, "id");
this.mydatagrid.DataKeyField = "id";
this.mydatagrid.DataSource = ds.Tables["id"].DefaultView;
this.mydatagrid.DataBind();
}
protected void mydatagrid_DeleteCommand(object source, DataGridCommandEventArgs e)
{
int id = Convert.ToInt32(this.mydatagrid.DataKeys[e.Item.ItemIndex].ToString());
cn = sqldata.createcon();
cn.Open();
strsql1 = "delete from Bed where id=" +id;
cmd1 = new SqlCommand(strsql1, cn);
cmd1.ExecuteNonQuery();
this.databindlist();
this.lbltishi.Text = "删除成功";
}
protected void mydatagrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#d3d3d3'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
((LinkButton)(e.Item.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('您确认要删除吗?');");
}
}
protected void mydatagrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.mydatagrid.CurrentPageIndex = e.NewPageIndex;
this.databindlist();
}
不知道对你有没有用 你看一下吧!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询