SqlConnection con = new SqlConnection("Data Source=192.168.1.30;Initial Catalog=schr_hg;User ID=sa;Password=dbpasssys;");
int index = GridView1.SelectedIndex;//获得行号
string y_no = GridView1.Rows[index].Cells[1].Text.ToString();
string sql = "select * from OA_ZX_Y where zx_y_no='" + y_no + "'";
SqlDataAdapter dt = new SqlDataAdapter(sql, con);
DataSet ds=new DataSet();
dt.Fill(ds, "oa_zx_y");
DataRowView dv = ds.Tables["oa_zx_y"].DefaultView[0];
foreach (GridViewRow gvr in GridView1.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 工号,但不是数据库主键
int index = GridView1.SelectedIndex;//获得行号
string y_no = GridView1.Rows[index].Cells[1].Text.ToString();
string sql = "select * from OA_ZX_Y where zx_y_no='" + y_no + "'";
SqlDataAdapter dt = new SqlDataAdapter(sql, con);
DataSet ds=new DataSet();
dt.Fill(ds, "oa_zx_y");
DataRowView dv = ds.Tables["oa_zx_y"].DefaultView[0];
foreach (GridViewRow gvr in GridView1.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 工号,但不是数据库主键
http://bbs.csdn.net/topics/370137834
http://blog.csdn.net/chinacsharper/article/details/15335339
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 + "");提示值沒被定義,是什麼問題?
http://www.cnblogs.com/insus/p/3219262.html
http://www.cnblogs.com/insus/archive/2011/10/27/2226703.html