小弟用showdata显示数据,已经设置好了显示"选择"
小弟的想法是:
点击"选择",然后学生的学号自动存储在session变量里,在这个页面的其他地方用.
可是总是提示index值不对.可是在另外的一个(有"编辑,更新,取消"按纽)的datagrid上面运行没有问题啊.而且明明是第二列是学号,(我把cells的值改成0,2...都不行).
private void showdata_SelectedIndexChanged(object sender, System.EventArgs e)
{
TextBox tb=new TextBox();
tb=(TextBox)showdata.SelectedItem.Cells[1].Controls[0]; //第二列是学号
Session["student_num"]=tb.Text.Trim(); //用Session存储学号,用来下面显示
}在线等待..................救命啊..............
小弟的想法是:
点击"选择",然后学生的学号自动存储在session变量里,在这个页面的其他地方用.
可是总是提示index值不对.可是在另外的一个(有"编辑,更新,取消"按纽)的datagrid上面运行没有问题啊.而且明明是第二列是学号,(我把cells的值改成0,2...都不行).
private void showdata_SelectedIndexChanged(object sender, System.EventArgs e)
{
TextBox tb=new TextBox();
tb=(TextBox)showdata.SelectedItem.Cells[1].Controls[0]; //第二列是学号
Session["student_num"]=tb.Text.Trim(); //用Session存储学号,用来下面显示
}在线等待..................救命啊..............
{
showdata.CurrentPageIndex=e.NewPageIndex;
//返回浏览状态
string sqlstring;
dbfunc Mydbfunc=new dbfunc();
sqlstring = "select [student_num] as 学号,[student_name] as 姓名 ,[student_sex] as 性别 from studentinfo where [student_num] in (select [student_num] from fclass where [class_num]="+input_class.SelectedValue +")";
showdata.DataSource=Mydbfunc.ReturnDS(sqlstring);
showdata.DataBind();
}
private void showdata_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TextBox tb=new TextBox();
tb=(TextBox)showdata.SelectedItem.Cells[1].Controls[0]; //第二列是学号
Session["student_num"]=tb.Text.Trim(); //用Session存储学号,用来下面显示
}
{
TextBox tb=new TextBox();
tb=(TextBox)e.Item.Cells[1].Controls[0];<-----------提示这里有错误
Session["num"]=tb.Text.Trim();
}
//这样的话,提示:指定的参数已超出有效值的范围。参数名: index
//要是该成cells[0]提示转换无效
//要是改成cells[2]...cell[5]都提示:指定的参数已超出有效值的范围。参数名: index
改成
Session["num"]=e.Item.Cells[1].Text.ToString()