问题描述
SqlConnectioncon=newSqlConnection("DataSource=192.168.1.30;InitialCatalog=schr_hg;UserID=sa;Password=dbpasssys;");intindex=GridView1.SelectedIndex;//获得行号stringy_no=GridView1.Rows[index].Cells[1].Text.ToString();stringsql="select*fromOA_ZX_Ywherezx_y_no='"+y_no+"'";SqlDataAdapterdt=newSqlDataAdapter(sql,con);DataSetds=newDataSet();dt.Fill(ds,"oa_zx_y");DataRowViewdv=ds.Tables["oa_zx_y"].DefaultView[0];foreach(GridViewRowgvrinGridView1.Rows){txt_No.Text=gvr.Cells[1].Text.ToString();txt_Name.Text=gvr.Cells[2].Text.ToString();txt_Bumen.Text=gvr.Cells[3].Text.ToString();txt_Kebie.Text=gvr.Cells[4].Text.ToString();txt_Zubie.Text=gvr.Cells[5].Text.ToString();}zx_y_no工号,但不是数据库主键
解决方案
解决方案二:
GridView1_SelectedIndexChanged事件,取不到值
解决方案三:
解决方案四:
GridView1_RowDataBound事件e.Row.Attributes.Add("onclick","document.getElementById('txt_No').value="+e.Row.Cells[1].Text+"");e.Row.Attributes.Add("onclick","document.getElementById('txt_Name').value="+e.Row.Cells[2].Text+"");e.Row.Attributes.Add("onclick","document.getElementById('txt_Bumen').value="+e.Row.Cells[3].Text+"");e.Row.Attributes.Add("onclick","document.getElementById('txt_Zubie').value="+e.Row.Cells[4].Text+"");e.Row.Attributes.Add("onclick","document.getElementById('txt_Kebie').value="+e.Row.Cells[5].Text+"");提示值沒被定義,是什麼問題?
解决方案五:
看看这: