日期:2014-05-18  浏览次数:20456 次

50分求一事件代码
单击Datagird取当前鼠标所在的行的前3个数据放到TextBox1、TextBox2、TextBox3
怎么做啊   我只要代码   web   求到就散分

------解决方案--------------------
首先:我加一了个模板列,并设为不可见.
<asp:TemplateColumn Visible= "False ">
<ItemTemplate>
<asp:Label runat= "server " Text= "Label "> </asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn CommandName= "Select " Text= "选择 "> </asp:ButtonColumn>


代码:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection( "server=192.168.0.101;uid=sa;pwd=yanfa;database=yygy ");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter( "select * from score ", conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();

}
protected void DataGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DataGrid1.SelectedItemStyle.BackColor = Color.Coral;

}
protected void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
{
this.TextBox1.Text = e.Item.Cells[2].Text;
this.TextBox2.Text = e.Item.Cells[3].Text;
this.TextBox3.Text = e.Item.Cells[4].Text;


}
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
{
e.Item.Attributes.Add( "OnClick ", Page.GetPostBackClientEvent(e.Item.Cells[1].Controls[0], String.Empty));

}
}

经测试,可以达到楼主的要求.