1

我目前有一个通过 ac# 方法通过数据库填充的 gridview。

我想知道是否有一种方法可以在单击行上的任意位置时选择该行而不完全使用选择按钮。然后将该行中的信息发回并填充网页上的另一个区域。

有没有比gridview更好的网格?我应该外包给 jQuery 吗?还是我只需要gridview?

4

1 回答 1

1

你需要做的是开发一个行可点击的 GridView。最好的办法是按照链接中的说明进行操作。如果你对VB没问题,你可以沿着这条路走。用户也将其转换为 C#,在评论部分。生病包括它以防你没有看到它。

这是我保存的链接:http: //aspadvice.com/blogs/joteke/archive/2006/01/07/14576.aspx

using System; 
using System.ComponentModel; 
using System.Configuration; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace CustomGridView 
{ 
 /// <summary> 
 /// Summary description for ClickableGridView 
 /// </summary> 
 public class ClickableGridView : GridView 
 { 
   public string RowCssClass 
   { 
     get 
     { 
       string rowClass = (string)ViewState["rowClass"]; 
       if (!string.IsNullOrEmpty(rowClass)) 
         return rowClass; 
       else 
         return string.Empty; 
     } 
     set 
     { 
       ViewState["rowClass"] = value; 
     } 
   } 

   public string HoverRowCssClass 
   { 
     get 
     { 
       string hoverRowClass = (string)ViewState["hoverRowClass"]; 
       if (!string.IsNullOrEmpty(hoverRowClass)) 
         return hoverRowClass; 
       else 
         return string.Empty; 
     } 
     set 
     { 
       ViewState["hoverRowClass"] = value; 
     } 
   } 

   private static readonly object RowClickedEventKey = new object(); 

   public event GridViewRowClicked RowClicked; 
   protected virtual void OnRowClicked(GridViewRowClickedEventArgs e) 
   { 
     if (RowClicked != null) 
       RowClicked(this, e); 
   } 

   protected override void RaisePostBackEvent(string eventArgument) 
   { 
     if (eventArgument.StartsWith("rc")) 
     { 
       int index = Int32.Parse(eventArgument.Substring(2)); 
       GridViewRowClickedEventArgs args = new GridViewRowClickedEventArgs(Rows[index]); 
       OnRowClicked(args); 
     } 
     else 
       base.RaisePostBackEvent(eventArgument); 
   } 

   protected override void PrepareControlHierarchy() 
   { 
     base.PrepareControlHierarchy(); 

     for (int i = 0; i < Rows.Count; i++) 
     { 
       string argsData = "rc" + Rows[i].RowIndex.ToString(); 
       Rows[i].Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(this, argsData)); 

       if (RowCssClass != string.Empty) 
         Rows[i].Attributes.Add("onmouseout", "this.className='" + RowCssClass + "';"); 

       if (HoverRowCssClass != string.Empty) 
         Rows[i].Attributes.Add("onmouseover", "this.className='" + HoverRowCssClass + "';"); 
     } 
   } 
 } 

 public class GridViewRowClickedEventArgs : EventArgs 
 { 
   private GridViewRow _row; 

   public GridViewRowClickedEventArgs(GridViewRow aRow) 
     : base() 
   { 
     _row = aRow; 
   } 

   public GridViewRow Row 
   { 
     get 
     { return _row; } 
   } 
 } 

 public delegate void GridViewRowClicked(object sender, GridViewRowClickedEventArgs args); 
} 
于 2012-08-07T20:25:41.037 回答