日期:2014-05-19  浏览次数:20975 次

急急急!!!!gridview 问题
点击gridview的某一行的任何一个地方,如何能取到点击的是哪一行???

------解决方案--------------------
太简单了 在gv的mouseup事件里面
如此这般//datagrid的整行选择
private void dg_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
//整行选择
if(e.Button==System.Windows.Forms.MouseButtons.Left)
{
dg.Select(dg.CurrentRowIndex);
tt_id.Text=dg[dg.CurrentCell.RowNumber,0].ToString();
tt_name.Text=dg[dg.CurrentCell.RowNumber,1].ToString();
}
if(dg[dg.CurrentCell].GetType().ToString()== "System.Boolean ")
{
if(dg[dg.CurrentCell].ToString()== "True ")
{
dg[dg.CurrentCell]=false;
}
else
{
dg[dg.CurrentCell]=true;
}
}
}
------解决方案--------------------
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes[ "OnClick "] = ClientScript.GetPostBackEventReference(this, "Select$ " + e.Row.RowIndex);
e.Row.Style[ "cursor "] = "hand ";
}
}