DataGrid的OnUpate问题

javanow 2002-03-12 12:39:23
我想在一个DataGrid里点编辑后,能出现一个 ListBox行吗?
另外,我想默认出现的 TextBox的TextMode 是TextBoxMode.MultiLine.
好像也不行。
各位高手能帮帮忙吗?
哎,我越来越没信心了
...全文
31 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
javanow 2002-03-12
  • 打赏
  • 举报
回复
谢谢 jerryfangsh(傻瓜) 教给我的简单方法
昨天我看sdk都看昏了,跳来跳去~

新版我连给分都不会了,我再试试
javanow 2002-03-12
  • 打赏
  • 举报
回复
非常谢谢 jerryfangsh(傻瓜)
给我的简单的方法。
大家都有
jerryfangsh 2002-03-12
  • 打赏
  • 举报
回复
在使用Templates时,给放在其中的DropDownList一个ID.<BR>
例如:<BR>
<ItemTemplate><BR>
<ASP:DropDownList runat="Server" ID="ddlDropDownList"></ASP:DropDownList>
<ItemTemplate><BR>
然后使用FindControl.<BR>
DropDownList ddlDropDownList1=(DropDownList)e.Item.FindControl("ddlDropDownList");
jdpopo 2002-03-12
  • 打赏
  • 举报
回复
我给一段我自己写的程序你看看吧,不过我没有用DropDownList,我想也应该差不多!或许对你有帮助!

protected void DataGrid1_Update(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs E)
{
int UserID =(int)DataGrid1.DataKeys[(int)E.Item.ItemIndex];

string UserName = ((TextBox)E.Item.Cells[1].Controls[0]).Text;
string Password=((TextBox)E.Item.Cells[2].Controls[0]).Text;
string UserType = ((TextBox)E.Item.Cells[3].Controls[0]).Text;
string UserRole = ((TextBox)E.Item.Cells[4].Controls[0]).Text;
string UserClass = ((TextBox)E.Item.Cells[5].Controls[0]).Text;

string strSql="UPDATE DevUser set UserName='" + UserName + "',Pwd='" + Password + "',UserType='" + UserType + "',UserRole='" + UserRole + "',UserClass='" + UserClass + "' where UserID=" + UserID;

string connstr=ConfigurationSettings.AppSettings["OleDbString"];
OleDbConnection MyConnection=new OleDbConnection(connstr);
MyConnection.Open();

OleDbCommand myCommand2= new OleDbCommand(strSql, MyConnection);
myCommand2.CommandType=CommandType.Text;
myCommand2.ExecuteNonQuery();

DataGrid1.EditItemIndex = -1;
List();
}
javanow 2002-03-12
  • 打赏
  • 举报
回复
我用Template后,倒是出来了一个 DropDownList

private void DataGrid_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//DropDownList DropDownList1 = (DropDownList)e.Item.Cells[9].Controls[0]; //status code
错误为:无法造型(Cast).
他几个范例我看不懂呀。
我该如何在 DataGrid_Update事件里得到那个 DropDownList 的值呢?
大家再帮帮我好吗?
我一定给分的
karma 2002-03-12
  • 打赏
  • 举报
回复
read the MSDN magazine article
"Understanding Templates in ASP.NET"
http://msdn.microsoft.com/msdnmag/issues/02/01/cutting/cutting0201.asp

for an example
zhq2000 2002-03-12
  • 打赏
  • 举报
回复
一、使用TemplateColumn:
在Property Builder对话框中,将该列换成Template,关闭对话框。
在DataGrid上右击,选编辑Template中的那一列,然后就可以在里面放入你所要的编辑控件。


二、通过事件ItemCreated完成:
在事件中:
if( e.Item.ItemType == ListItemType.EditItem )
{
TextBox t = new TextBox();
t.TextMode = TextMode.MultiLine;
e.Item.Cells[n].Controls.Clear();
e.Item.Cells[n].Controls.Add(t);
// n 为所要的列
}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧