我在page.aspx中有一個Gridview。這個gridview我想作爲參數傳遞給class1.cs.的構造函數。任何人都可以打電話給我,這怎麼辦?我如何訪問一個控件到一個類中?
0
A
回答
1
所以,你有一個網頁,一個GridView:
<asp:GridView runat="server" ID="gv1" AutoGenerateColumns="true">
</asp:GridView>
<div>
This is where the count of rows of your GridView will be displayed:
<p>
<strong><asp:Label runat="server" ID="lCount" /></strong>
</p>
</div>
而且,在代碼隱藏你填充它是這樣的:
this.gv1.DataSource = FullName.GetDemoCollection(); //Just returns a List<string>;
gv1.DataBind();
和你有另一個類GridViewRowCounter
做一些事GridView,例如計算行:
public class GridViewRowCounter
{
private System.Web.UI.WebControls.GridView _gv;
public GridViewRowCounter(){}
public GridViewRowCounter(System.Web.UI.WebControls.GridView _GV){
this._gv = _GV;
}
public int GetRowCount(){
return _gv.Rows.Count;
}
}
所以,你的GridView傳遞給Gridviewcounter類,你可以這樣做:
public partial class PassingControls : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Bind the GridView
this.gv1.DataSource = FullName.GetDemoCollection();//
gv1.DataBind();
//Pass Gridview reference to the GridVeiwRowCounter constructor.
GridViewRowCounter gvcounter = new GridViewRowCounter(this.gv1);
//Get the external class to return the rowcount from your GridView.
this.lCount.Text = gvcounter.GetRowCount().ToString();
}
}
HTH。
我希望這是你問;-)
+0
感謝花時間回答我,但是,對不起! ü誤解了我的問題。:-)其實我想傳遞的GridView作爲參數的一類事情是這樣的MyClass類 { 公共MYCLASS(GridView的GV) {// 一些代碼 } }上面的代碼需要在一個班上。 Gridview我想從.aspx頁面傳遞。我想一些命名空間必須添加到類中,以在構造函數中將gridview作爲數據類型。這個怎麼做? – Swathi 2011-01-28 04:47:30
相關問題
- 1. 如何使用c#訪問一個用戶控件到另一個控件?
- 2. 如何從一個類訪問JTextArea到另一個類
- 3. 如何從一個類訪問變量值到另一個類?
- 4. 如何在另一個類中訪問一個類數據庫?
- 5. 如何從另一個類訪問Winform文本框控件?
- 6. 如何從另一個類訪問控件?
- 7. 在Python中從一個類訪問變量到另一個類
- 8. pydev從一個文件到另一個文件中的另一個類訪問一個類的值
- 9. 如何訪問到一個HTML控件RUNAT服務器從JavaScript
- 10. 我如何才能訪問到另一個模型類屬性
- 11. 如何訪問一個JPanel組件到另一個JPanel
- 12. 如何在swift中訪問IBOutlet從一個類到其他類
- 13. 如何從自定義類中訪問另一個類/控件的屬性?
- 14. 如何訪問另一個包中的另一個類?
- 15. 如何將一個控件綁定到另一個控件?
- 16. 如何訪問另一個類的ArrayList
- 17. 如何從另一個類訪問notifyIcon
- 18. 如何從另一個類訪問textarea?
- 19. 如何從另一個類訪問ArrayList
- 20. 如何從另一個類訪問listview?
- 21. 如何從另一個類訪問getSharedPreferences?
- 22. 如何從另一個類訪問mainwindow?
- 23. 如何從另一個類訪問JButton
- 24. 訪問MainWIndow從一個單獨的文件中的類控制
- 25. 如何訪問另一個控件中的值
- 26. 從一個類訪問靜態變量到另一個類
- 27. 從一個類到另一個類的Java訪問信息
- 28. 從另一個類訪問一個NSMutableArray
- 29. 訪問一個ASP.Net用戶控件
- 30. 從另一個類文件中訪問一個方法?
哪個GridView的?或者這不是asp.net mvc? – alexn 2011-01-26 10:38:29