如:
((TextBox)e.Item.FindControl("tbName")).Text
这是一个TextBox的控件的值 ,其它的控件是两样的道理!!
((TextBox)e.Item.FindControl("tbName")).Text
这是一个TextBox的控件的值 ,其它的控件是两样的道理!!
解决方案 »
- ASP.NET声音播放
- 不同.Net Framework版本存在,应用程序不能运行
- asp.net RangeValidator验证悲催的问题
- 去过闪吧的人过来看一下,如何实现闪吧论坛里的快速回复功能,谢谢
- dropdownlist 会显示默名奇妙的数据,不是表的数据,数据是System.data.datarowview
- 关于DataGrid显示数据问题~~~急(在线等)
- 跟大家计论一个通用性的问题
- 请教SQL SERVER的问题~!
- DataGrid为什么不能分页?
- datagrid中的表格如何输出为txt文件?
- 高手帮帮我!!!急!有关文件操作
- 怎么提交过程中"<>/"等html标记的问题
{
String updateCmd = "UPDATE tongxunlu SET name=@Name,hphone=@Hphone,ophone=@Ophone,mphone=@Mphone,danwei=@Danwei,adress=@Adress where id =@Id";
SqlCommand myCommand = new SqlCommand(updateCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int, 4));
myCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.Char));
myCommand.Parameters.Add(new SqlParameter("@Hphone", SqlDbType.Char));
myCommand.Parameters.Add(new SqlParameter("@Ophone", SqlDbType.Char));
myCommand.Parameters.Add(new SqlParameter("@Mphone", SqlDbType.Char));
myCommand.Parameters.Add(new SqlParameter("@Danwei", SqlDbType.Char));
myCommand.Parameters.Add(new SqlParameter("@Adress", SqlDbType.Char));
myCommand.Parameters["@Id"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];
String[] cols = {"@Name","@Hphone","@Ophone","@Mphone","@Danwei","@Adress"};
int numCols = e.Item.Cells.Count;
for (int i=2; i<numCols; i++) //跳过第一、第二列
{
String colvalue =((TextBox)e.Item.Cells[i].Controls[0]).Text; myCommand.Parameters[cols[i-2]].Value = colvalue;
}
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
DataGrid1.EditItemIndex = -1;
BindGrid();
}
}
TextBox tb;
tb = (TextBox)e.Itme.Cell[0].Controls[0];
//tb.Text就是你编辑过的值了
TextBox tbox=(TextBox)e.Item.Cells[2].Controls[0];
string ss=tbox.Text;
对于模板列需要用到FindControl("控件id")
{
Lable1.Text=((TextBox)e.Item.Cells[0].Controls[0]).Text;
Lable2.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text;
.
.
.
}
Dim bt as Textbox
Dim ls_code as String
bt= e.Item.Cells(1).Controls(e.Item.ItemIndex)
ls_code = bt.Text
Response.Write(ls_code)
試試..
{
int i=e.Item.ItemIndex;
SqlData aSqlData = new SqlData();CONNECTION
aSqlData.Source.Close();
aSqlData.Source.Open();
int ff=Int32.Parse(aslw1.Rows[0]["cartoncount"].ToString());---->ASLW1--->DATATABLE
int g=Int32.Parse((aslwdgq.Rows[i]["totalcbm"].ToString()));
string t="null";
string mm="";
if(aslwdgq.Rows[i]["monthcontainerid"].ToString()=="" || aslwdgq.Rows[i]["monthcontainerid"].ToString()==null)
{
mm="null";
}
.......
Dim bt As TextBox = CType(e.Item.Cells(1).Controls(0),TextBox)
Dim ls_code as String = bt.Text
Response.Write(ls_code)
//更新按鈕事件處理。
TextBox name=(TextBox)e.Item.Cells[2].Controls[0];
TextBox data=(TextBox)e.Item.Cells[3].Controls[0];
TextBox talk=(TextBox)e.Item.Cells[4].Controls[0];
SqlConnection conn=new SqlConnection("user id=zjl;password=sa;database=mydb");
string sql="select * from test";
SqlDataAdapter ada = new SqlDataAdapter(sql,conn);
DataSet ds=new DataSet();
ada.Fill(ds,"test");
DataGrid1.DataSource=ds.Tables["test"].DefaultView;
DataGrid1.DataBind(); DataRow dr=ds.Tables["test"].Rows[(int)e.Item.ItemIndex];
dr["name"]=name.Text;
dr["data"]=data.Text ;
dr["talk"]=talk.Text;
//在這里如做下這是在頁面上修改了﹐存到頁面上了。
// DataGrid1.EditItemIndex = -1;
// DataGrid1.DataBind();
Response.Write(e.Item.ItemIndex.ToString()+"<br>");
Response.Write(name.Text.ToString()+"<br>");
Response.Write(data.Text.ToString()+"<br>");
Response.Write(talk.Text.ToString()+"<br>");
//以上為更新到源數據庫中﹕
SqlCommandBuilder bd= new SqlCommandBuilder();
ada.UpdateCommand=bd.GetUpdateCommand();
ada.InsertCommand=bd.GetInsertCommand();
ada.DeleteCommand=bd.GetDeleteCommand();
ada.Update(ds,"test"); ada.Update(ds,"test"); conn.Open();
ada=new SqlDataAdapter(sql,conn);
ada.Fill(ds,"test");
conn.Close();
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}