protected void Button1_Click(object sender, EventArgs e)
{
if (Session["MessId"] != null)
{
string MessId = Session["MessId"].ToString();
GridViewRow row = null;
foreach (GridViewRow iRow in this.GridView1.Rows)
if (iRow.Cells[0].Text == MessId)
row = iRow;
if (row != null)
{
Panel panel = (Panel)this.GridView1.SelectedRow.FindControl("Panel1");
TextBox text = (TextBox)panel.FindControl("TextBox1");
Session["ReplyMess"] = text.Text.ToString();
}
法2:
if (this.GridView1.SelectedRow.RowType == DataControlRowType.DataRow)
{
Panel panel = (Panel)this.GridView1.SelectedRow.FindControl("Panel1");
TextBox text = (TextBox)panel.FindControl("TextBox1");
Session["ReplyMess"] = text.Text.ToString();
}
textbox都取不到值啊,困惑我两天了,谢谢大家.
{
if (Session["MessId"] != null)
{
string MessId = Session["MessId"].ToString();
GridViewRow row = null;
foreach (GridViewRow iRow in this.GridView1.Rows)
if (iRow.Cells[0].Text == MessId)
row = iRow;
if (row != null)
{
Panel panel = (Panel)this.GridView1.SelectedRow.FindControl("Panel1");
TextBox text = (TextBox)panel.FindControl("TextBox1");
Session["ReplyMess"] = text.Text.ToString();
}
法2:
if (this.GridView1.SelectedRow.RowType == DataControlRowType.DataRow)
{
Panel panel = (Panel)this.GridView1.SelectedRow.FindControl("Panel1");
TextBox text = (TextBox)panel.FindControl("TextBox1");
Session["ReplyMess"] = text.Text.ToString();
}
textbox都取不到值啊,困惑我两天了,谢谢大家.
{
if (Session["MessId"] != null)
{
string MessId = Session["MessId"].ToString();
GridViewRow row = null;
foreach (GridViewRow iRow in this.GridView1.Rows)
if (iRow.Cells[0].Text == MessId)
row = iRow;
if (row != null)
{
Panel panel = (Panel)row.FindControl("Panel1");//改一下这里
TextBox text = (TextBox)panel.FindControl("TextBox1");
Session["ReplyMess"] = text.Text.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack) BindDate();
}由于每次postback时,都会先执行Page_Load,也就重新绑定GridView,里面的TextBox肯定就找不到了~
{
Panel panel = (Panel)this.gridview.Rows[i].Cells[PanelIndex].Controls[1];
TextBox textBox = (TextBox)panel.Controls[i];
}上面PanelIndex是你 Panel放在gridview的第几列
在dropdownlist 的selectedindexchange 里再 BindDate();
(dropdownlist 要autopostback=true;