日期:2014-05-18  浏览次数:20504 次

VS2008編輯gridview獲取不到文本框的值
protected void dgvMain_RowUpdating(object sender, GridViewUpdateEventArgs e)
  { 
  TextBox txtScheduledate = dgvMain.Rows[e.RowIndex].FindControl("txtSchedule_date") as TextBox;
  TextBox txtLeatherdate = dgvMain.Rows[e.RowIndex].FindControl("txtLeather_date") as TextBox;
  TextBox txtInsidedate = dgvMain.Rows[e.RowIndex].FindControl("txtInside_date") as TextBox;
  TextBox txtOutsoledate = dgvMain.Rows[e.RowIndex].FindControl("txtOutsole_date") as TextBox;
  TextBox txtNotes = dgvMain.Rows[e.RowIndex].FindControl("txtNotes") as TextBox;
}

------解决方案--------------------
C# code

 string ProjectItem = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();

------解决方案--------------------
up!
------解决方案--------------------
1楼。
------解决方案--------------------
<EditItemTemplate>
<asp:TextBox id="txtSchedule_date" runat="server" Width="89%" CssClass="inputText" Text='<%# Eval("Scheduledate") %>' >
</asp:TextBox>
</EditItemTemplate>
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

string strId = gvRole.DataKeys[e.RowIndex].Value.ToString();

string str = ((TextBox)gv.Rows[e.RowIndex].FindControl("txtSchedule_date")).Text.Trim();
}

------解决方案--------------------
      protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{      
sqlcon = new SqlConnection(strCon);      
  string sqlstr = "update 表 set 字段1='"            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',字段2='"            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',字段3='"            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' where id='"             + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";      
  sqlcom=new SqlCommand(sqlstr,sqlcon);       
 sqlcon.Open();       
 sqlcom.ExecuteNonQuery();    
    sqlcon.Close();      
  GridView1.EditIndex = -1;
}
------解决方案--------------------
up........
------解决方案--------------------
string aaa=Convert.ToDecimal(((TextBox)(ProGridView.Rows[e.RowIndex].Cells [4].Controls[0])).Text.ToString().Trim());
------解决方案--------------------
C# code

TextBox txtScheduledate=(TextBox)dgvMain.Rows[e.RowIndex].Cells[0].FindControl("txtSchedule_date");

//或者:
TextBox txtScheduledate=(TextBox)dgvMain.Rows[e.RowIndex].Cells[0].Controls[1]

------解决方案--------------------
LZ 你为什么一定要用控件啊。。。循环一个表格不行吗?