| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 389 人关注过本帖
标题:关于DataGrid控件的问题
只看楼主 加入收藏
lbwxqh
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2006-4-12
收藏
 问题点数:0 回复次数:1 
关于DataGrid控件的问题

在页面上添加了一个DataGrid控件,定义代码如下:
<asp:label id="welcomemsg" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 80px"
runat="server" Width="352px">Label</asp:label><asp:datagrid id="info" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 112px" runat="server"
Width="662px" AutoGenerateColumns="False" Height="280px" PageSize="5" ItemStyle-Wrap="False">
<ItemStyle Wrap="False"></ItemStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="update" HeaderText="command" CancelText="cancel"
EditText="edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="username" ReadOnly="True" HeaderText="用户名"></asp:BoundColumn>
<asp:BoundColumn DataField="realname" HeaderText="真实姓名"></asp:BoundColumn>
<asp:BoundColumn DataField="sex" HeaderText="性别"></asp:BoundColumn>
<asp:BoundColumn DataField="birthday" HeaderText="生日"></asp:BoundColumn>
<asp:BoundColumn DataField="licencetype" HeaderText="证件类型"></asp:BoundColumn>
<asp:BoundColumn DataField="licencenumber" HeaderText="证件号码"></asp:BoundColumn>
<asp:BoundColumn DataField="email" HeaderText="EMAIL"></asp:BoundColumn>
<asp:BoundColumn DataField="love" HeaderText="爱好"></asp:BoundColumn>
<asp:BoundColumn DataField="address" HeaderText="住址"></asp:BoundColumn>
</Columns>
</asp:datagrid>
然后为其添加UPDATE事件代码如下:
public void info_update(object sender,DataGridCommandEventArgs e)
{
string myname=e.Item.Cells[1].Text;
string realname=((TextBox)e.Item.Cells[2].Controls[0]).Text;
TextBox sex=(TextBox) e.Item.Cells[3].Controls[0];
TextBox birthday=(TextBox) e.Item.Cells[4].Controls[0];
TextBox licencetype=(TextBox)e.Item.Cells[5].Controls[0];
TextBox licencenumber=(TextBox)e.Item.Cells[6].Controls[0];
TextBox email=(TextBox)e.Item.Cells[7].Controls[0];
TextBox love=(TextBox)e.Item.Cells[8].Controls[0];
TextBox address=(TextBox)e.Item.Cells[9].Controls[0];
mydataset.Tables["userinfo"].DefaultView.RowFilter="username='"+myname+"'";
if(mydataset.Tables["userinfo"].DefaultView.Count>0)
mydataset.Tables["userinfo"].DefaultView.Delete(0);
mydataset.Tables["userinfo"].DefaultView.RowFilter="";
DataRow myrow=mydataset.Tables["userinfo"].NewRow();
myrow[0]=myname;
myrow[2]=realname;
myrow[3]=sex.Text;
myrow[4]=birthday.Text;
myrow[5]=licencetype.Text;
myrow[6]=licencenumber.Text;
myrow[7]=email.Text;
myrow[8]=love.Text;
myrow[9]=address.Text;
mydataset.Tables["userinfo"].Rows.Add(myrow);
welcomemsg.Text=myname+realname+sex.Text+birthday.Text+licencetype.Text;
info.EditItemIndex=-1;
info.DataSource=mydataset;
info.DataBind();
}
那个welcomemsg是一个LABEL控件,是本人用来记录用户修改后的数据的,但是出现了一个题,我修改了数据按UPDATE后,在welcomemsg中显示的还是原来从数据库调出来的值,并没有显示用户修改后的数据,网格刷新后显示的也还是原来的数据,不知道是什么原因,望高手指点,谢谢!

搜索更多相关主题的帖子: DataGrid 控件 
2006-07-28 20:43
caiyakang
Rank: 2
等 级:新手上路
威 望:5
帖 子:2111
专家分:0
注 册:2005-3-24
收藏
得分:0 

把绑定到DATAGRID写成一个方法如BindData()
修改后重新BindData()


中国人的财富网:http://www..cn/
2006-07-29 20:46
快速回复:关于DataGrid控件的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012162 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved