DataList 动态更新问题,和数据显示问题
如何实现在web页面上点添加按钮后,DataList及时把所添加的内容显示出来
还有为什么,我的表是
'kind表
ID Fid name
1 0 小明
2 0 小王
3 1 小红
4 1 小红
5 1 小红
6 1 小方
7 1 小方
8 1 小李
我用的sql 是 select * from kind where fid=1"
DataList 里只显示
小红
小方
小李
也就是 name字段重复的值它不显示
我的部分关键源码
页面webForm1
………
………
private void Page_Load(object sender, System.EventArgs e)
{
XDown.nClasss mynclass=new XDown.nClasss();
DataList1.DataSource=mynclass.GetFartherList();
DataList1.DataBind();
}
…………
………
private void Button1_Click(object sender, System.EventArgs e)
{
XDown.nClasss mynclass=new XDown.nClasss();
if(mynclass.AddFartherKind(TextBox1.Text))
{
Label1.Text="添加成功!";
}
else
{
Label1.Text="添加失败!";
}
DataList1.DataSource=mynclass.GetFartherList();
DataList1.DataBind();
}
…………
====================================================================
Nclass.cs
//***************************************************************************************************
//
//函数GetChildList()得到子类分类列表
//参数fid : 子类所属的父类ID
//
//***************************************************************************************************
public OleDbDataReader GetChildList(int fid)
{
string SQL="select * from nclass where fartherid="+fid;
OleDbConnection myConn=new OleDbConnection(ConfigurationSettings.AppSettings["connectionstring"]);
OleDbCommand myCmd=new OleDbCommand(SQL,myConn);
myConn.Open();
OleDbDataReader result=myCmd.ExecuteReader(CommandBehavior.CloseConnection);
return result;
}
//***************************************************************************************************
//
//函数AddChildKind()得到子类分类列表
//参数fid : 子类所属的父类ID
//
//***************************************************************************************************
public bool AddChildKind(int fid,string kindname)
{
string SQL="insert into nclass (fartherid,kindname) values ('"+fid+"','"+kindname+"')";
OleDbConnection myConn=new OleDbConnection(ConfigurationSettings.AppSettings["connectionstring"]);
OleDbCommand myCmd=new OleDbCommand(SQL,myConn);
try
{
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close();
return true;
}
catch
{
return false;
}
}