DataGrid 第二例是checkbox,第一列是id值,如何得到checkbox选中的id值?

解决方案 »

  1.   

    问题一:如果checkbox的值是从数据库中取出的,你可以通过SQL查询得到选中checkbox的的id。
    问题二:“删除”可以作为超级连接列,通过传递的ID参数,来执行SQL语句,进行删除。
      

  2.   

    假设你的DataGrid的ID为show,然后创建它的ItemDataBound事件。
    private void show_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType==System.Web.UI.WebControls.ListItemType.Item||e.Item.ItemType==System.Web.UI.WebControls.ListItemType.AlternatingItem||e.Item.ItemType==System.Web.UI.WebControls.ListItemType.EditItem||e.Item.ItemType==System.Web.UI.WebControls.ListItemType.SelectedItem)
    {
    e.Item.Attributes["onmouseover"]="currentcolor=this.style.backgroundColor;this.style.backgroundColor='Gainsboro'";
    e.Item.Attributes["onmouseout"]="this.style.backgroundColor=currentcolor";
    } }
      

  3.   

    protected void GongshiGridview_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer)
            {   e.Row.Attributes.Add("onclick", "window.open('Busdetail.aspx?id2=" + ID2.ToString() + "&id1=" + ID1.ToString() + "')");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"" + "#EFFFFF" + "\"");
            }
    第一句是单击行跳转一个新页面