如何在不使用Gridview控件的情况下搜索,关闭,插入,更新,删除,移动上一个并移动下一个记录..? [英] How Do I Search , Close, Insert,Update,Delete, Move Previous And Move Next Record Without Gridview Control..?
本文介绍了如何在不使用Gridview控件的情况下搜索,关闭,插入,更新,删除,移动上一个并移动下一个记录..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void getdata()
{
txteno.Text = ds.Tables[0].Rows[rno][0].ToString();
txtenme.Text = ds.Tables[0].Rows[rno][1].ToString();
txtjob.Text = ds.Tables[0].Rows[rno][2].ToString();
txtloc.Text = ds.Tables[0].Rows[rno][3].ToString();
txtpno.Text = ds.Tables[0].Rows[rno][4].ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
string scon = ConfigurationManager.ConnectionStrings["scn"].ConnectionString;
cn = new SqlConnection(scon);
da = new SqlDataAdapter("select * from emphalf", cn);
ds = new DataSet();
da.Fill(ds, "emphalf");
getdata();
}
protected void btnprev_Click(object sender, EventArgs e)
{
if (rno > 0)
{
rno -= 1;
if (ds.Tables[0].Rows[rno].RowState == DataRowState.Deleted)
{
// DataRow dr = (DataRow)ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];
Response.Write("deleted row data cannot be accessed");
return;
}
getdata();
}
else Response.Write("first record");
}
protected void btnxt_Click(object sender, EventArgs e)
{
if (rno < ds.Tables[0].Rows.Count - 1)
{
rno += 1;
if (ds.Tables[0].Rows[rno].RowState == DataRowState.Deleted)
{
Response.Write("deleted row data cannot be accessed");
return;
}
getdata();
}
else Response.Write("last record");
}
protected void btninsert_Click(object sender, EventArgs e)
{
DataRow dr = ds.Tables[0].NewRow();
dr[0] = txteno.Text;
dr[1] = txtenme.Text;
dr[2] = txtjob.Text;
dr[3] = txtloc.Text;
dr[4] = txtpno.Text;
ds.Tables[0].Rows.Add(dr);
rno = ds.Tables[0].Rows.Count - 1;
Response.Write("data row is added");
getdata();
}
protected void btnupdate_Click(object sender, EventArgs e)
{
ds.Tables[0].Rows[rno][1] = txtenme.Text;
ds.Tables[0].Rows[rno][2] = txtjob.Text;
ds.Tables[0].Rows[rno][3] = txtloc.Text;
ds.Tables[0].Rows[rno][4] = txtpno.Text;
Response.Write("data row is updated");
getdata();
}
protected void btndelete_Click(object sender, EventArgs e)
{
ds.Tables[0].Rows[rno].Delete();
Response.Write("data row is deleted");
getdata();
}
protected void btnsave_Click(object sender, EventArgs e)
{
cb = new SqlCommandBuilder(da);
da.Update(ds, "emphalf");
Response.Write("data is saved to database");
getdata();
}
推荐答案
使用Gridview时可以使用转发器或Datalist
Insted of using Gridview you can use repeater or Datalist
这篇关于如何在不使用Gridview控件的情况下搜索,关闭,插入,更新,删除,移动上一个并移动下一个记录..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文