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;
}
[解决办法]
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());
[解决办法]
TextBox txtScheduledate=(TextBox)dgvMain.Rows[e.RowIndex].Cells[0].FindControl("txtSchedule_date");//或者:TextBox txtScheduledate=(TextBox)dgvMain.Rows[e.RowIndex].Cells[0].Controls[1]
[解决办法]
LZ 你为什么一定要用控件啊。。。循环一个表格不行吗?
对简单啊。效率还好
[解决办法]
foreach(GridViewRow row in GridView1.Rows)
{
TextBox tb=row.FindControl("TextBox1") as TextBox;
tb.Text="";
}
[解决办法]
TextBox txtScheduledate = dgvMain.Rows[e.RowIndex].FindControl("txtSchedule_date") as TextBox;
你这样是定义一个变量txtScheduledate(他是个TextBox类型的)要取值,你还得
strin aaa= txtSchedudedate.text.toString();
[解决办法]
<asp:TemplateField HeaderText="姓名"> <ItemTemplate> <asp:Label ID="lblEmpRealName" runat="server" Text='<%#Eval("EmpRealName") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtEmpRealName" runat="server" Text='<%#Eval("EmpRealName") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField>