首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

GridView更新时,取出更新的TextBox值为什么取的有有关问题

2012-02-14 
GridView更新时,取出更新的TextBox值为什么取的有问题?asp:GridViewID dgvListPic DataKeyNames ID

GridView更新时,取出更新的TextBox值为什么取的有问题?
<asp:GridView   ID= "dgvListPic "   DataKeyNames= "ID "   PageSize= "3 "   AllowPaging= "true "   AllowSorting= "true "   AutoGenerateColumns= "false "   EmptyDataText= "no   data! "   runat= "server "   onPageIndexChanging= "dgvListPic_PageIndexChanging "   OnRowEditing= "dgvListPic_RowEditing "   OnRowCancelingEdit= "dgvListPic_RowCancelingEdit "   OnRowUpdating= "dgvListPic_RowUpdating "   width= "500 "   height= "300 ">
<columns>
<asp:BoundField   DataField= "ID "   HeaderText= "ID "> </asp:BoundField>
<asp:TemplateField   HeaderText= "图片名 ">
<itemtemplate>
<asp:Label   ID= "lblPicName "   runat= "server "> <%#   DataBinder.Eval(Container.DataItem,   "UploadName ")   %> </asp:Label>
</itemtemplate>
<edititemtemplate>
<asp:TextBox   ID= "txtPicName "   runat= "server "   Text= ' <%#   DataBinder.Eval(Container.DataItem,   "UploadName ")   %> '> </asp:TextBox>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield   HeadertEXT= "操作 ">
<itemtemplate>
<asp:LinkButton   ID= "lbtnEdit "   runat= "server "   CommandName= "Edit "   Text= "编辑 "   CausesValidation= "false "   OnClientClick= "return   Confirm( '你确定要编辑吗? '); "   />
<asp:LinkButton   ID= "lbtnDelete "   runat= "server "   CommandName= "Delete "   Text= "删除 "   onClientClick= "return   Confirm( '你确定要删除吗? '); "   />
<asp:LinkButton   ID= "lbtnSelect "   runat= "server "   CommandName= "Select "   Text= "选择 "   />
</itemtemplate>
<edititemtemplate>
<asp:LinkButton   ID= "lbtnUpdate "   runat= "server "   CommandName= "Update "   Text= "修改 "   />
<asp:LinkButton   ID= "lbtnCancel "   runat= "server "   CommandName= "Cancel "   Text= "取消 "   />
</edititemtemplate>
</asp:templatefield>
</columns>
<AlternatingRowStyle   BackColor= "#EFEFEF "   />
</asp:GridView>

c#

//更新操作
protected   void   dgvListPic_RowUpdating(Object   sender,   GridViewUpdateEventArgs   e)
{
string   ID   =   dgvListPic.DataKeys[e.RowIndex].Values[0].ToString();
string   dbPicName   =   ((TextBox)dgvListPic.Rows[e.RowIndex].FindControl( "txtPicName ")).Text;
OleDbConnection   con   =   createConn();
con.Open();
string   strSql   =   "UPDATE   Upload   SET   UploadName   =   ' "   +   dbPicName   +   " '   WHERE   ID= "+ID;
Response.Write( " <scr "+ "ipt> alert( ' "+dbPicName+ " ') </sc "+ "ript> ");
OleDbCommand   cmd   =   new   OleDbCommand(strSql,   con);
Response.Write(strSql);
Response.End();
cmd.ExecuteNonQuery();


con.Close();
dgvListPic.EditIndex   =   -1;
dgvListPic_DataBind();
}
为什么我无论更新哪条记录。取出的dbPicName都是一样的值,我明明在txtPicName里输入了值啊!

[解决办法]
ding
[解决办法]
GridView1更新事件:

protected void LinkButton1_Click1(object sender, EventArgs e)
{
int index = GridView1.EditIndex;
GridViewRow row = GridView1.Rows[index];
string id = row.Cells[0].Text.ToString(); //注意row大小写
//string qymc = row.Cells[1].Text.ToString(); //注意row大小写
string qymc = ((TextBox)row.Cells[1].Controls[0]).Text; //注意
string jgdm = ((TextBox)row.Cells[2].Controls[0]).Text; //注意
[解决办法]
string key = dgvListPic.DataKeys[e.RowIndex].Value.ToString();
string txt = ((TextBox)dgvListPic.Rows[e.RowIndex].Cells[???-表格位置].Controls[0]).Text;

热点排行