蓝
蓝叶菱
Unregistered / Unconfirmed
GUEST, unregistred user!
ASP.NET关于GridView的删除问题,我打算使用SQL 进行删除,但是怎么取得当前的ID啊?
public partial class adminuserview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack){
BindGrid();
}
}
private void BindGrid()
{
string connstr = System.Configuration.ConfigurationSettings.AppSettings["xaHome"];
SqlConnection conn = new SqlConnection(connstr);
//设置适配器
SqlDataAdapter da = new SqlDataAdapter("select * from k_user",conn);
//创建客户端DataSet
DataSet ds = new DataSet();
try
{
da.Fill(ds,"mtable"
//开始绑定,根据内容表设置数据源,并且绑定
GridView1.DataSource=ds;
GridView1.DataBind();
}
catch(Exception error){
Response.Write(error.ToString());
}
}
[red] protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//----------这里不知道怎么写了!!!!!!!!!!!!!!!!!!
string connstr = System.Configuration.ConfigurationSettings.AppSettings["xaHome"];
SqlConnection conn = new SqlConnection(connstr);
//---
String logText = "";
// Append the values of the key fields to the log text.
foreach (DictionaryEntry keyEntry in e.Keys)
{
logText += keyEntry.Key + "="
+ keyEntry.Value + ";";
}
// Append the values of the non-key fields to the log text.
foreach (DictionaryEntry valueEntry in e.Values)
{
logText += valueEntry.Key + "="
+ valueEntry.Value + ";";
}
// Display the log content.
Label1.Text = logText;
/*
SqlCommand qdml = new SqlCommand();
qdml.Connection = conn;
qdml.CommandType = CommandType.Text;
qdml.CommandText=String.Format("delete from k_user where id={0}",GridView1.
*/
}
}[/red]
public partial class adminuserview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack){
BindGrid();
}
}
private void BindGrid()
{
string connstr = System.Configuration.ConfigurationSettings.AppSettings["xaHome"];
SqlConnection conn = new SqlConnection(connstr);
//设置适配器
SqlDataAdapter da = new SqlDataAdapter("select * from k_user",conn);
//创建客户端DataSet
DataSet ds = new DataSet();
try
{
da.Fill(ds,"mtable"
//开始绑定,根据内容表设置数据源,并且绑定
GridView1.DataSource=ds;
GridView1.DataBind();
}
catch(Exception error){
Response.Write(error.ToString());
}
}
[red] protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//----------这里不知道怎么写了!!!!!!!!!!!!!!!!!!
string connstr = System.Configuration.ConfigurationSettings.AppSettings["xaHome"];
SqlConnection conn = new SqlConnection(connstr);
//---
String logText = "";
// Append the values of the key fields to the log text.
foreach (DictionaryEntry keyEntry in e.Keys)
{
logText += keyEntry.Key + "="
+ keyEntry.Value + ";";
}
// Append the values of the non-key fields to the log text.
foreach (DictionaryEntry valueEntry in e.Values)
{
logText += valueEntry.Key + "="
+ valueEntry.Value + ";";
}
// Display the log content.
Label1.Text = logText;
/*
SqlCommand qdml = new SqlCommand();
qdml.Connection = conn;
qdml.CommandType = CommandType.Text;
qdml.CommandText=String.Format("delete from k_user where id={0}",GridView1.
*/
}
}[/red]