获取不到Grid View里TextBox的值 TextBox用模板添加的 'txtScore' ( 大侠快进)
后台代码如下: 先用DropDownList获得课程名称,在绑定Grid View数据,再Grid View里的TextBox输入成绩后点击 btnSubmit 来获取输入的成绩,但是就是显示不出来,也没提示错误,测试了btnSubmit里的语句,也没有错,不知道什么问题,大侠帮忙看看阿?
public partial class teacherSubmitScore : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userName"] == null )
{
Response.Redirect("Login.aspx");
}
if (!IsPostBack)
{
BindDDL();
}
BindGridView();
}
private void BindDDL()
{
string strconnection = ConfigurationManager.ConnectionStrings["zilong"].ConnectionString;
SqlConnection conn = new SqlConnection(strconnection);
string SqlStr = "select distinct Course.courseID,Course.courseName from Elect,Course where Elect.teaID=Course.teaID and Elect.teaID='" + Session["userName"].ToString() + "'"; //查询所教授的课程
DataSet ds = new DataSet();
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
da.Fill(ds);
conn.Close();
ddl.DataSource = ds.Tables[0].DefaultView;
ddl.DataTextField = "courseName";
ddl.DataValueField = "courseID";
ddl.DataBind();
}
private void BindGridView()
{
string strconnection = ConfigurationManager.ConnectionStrings["zilong"].ConnectionString;
SqlConnection conn = new SqlConnection(strconnection);
GridView1.Visible = true;
string Sqlstr = "select * from Student,Elect where Student.stuID=Elect.stuID and Elect.courseID='" + ddl.SelectedValue + "'";
DataSet ds = new DataSet();
try
{
if (conn.State.ToString() == "Closed")
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(Sqlstr, conn);
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
catch{ }
finally
{ conn.Close();}
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
string text = ((TextBox)GridView1.Rows[i].FindControl("txtScore")).Text.ToString;
Response.Write(text);
}
}
}