UserControl里面的GridView

UserControl里面的GridView

本文介绍了UserControl里面的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在UserControl中有一个gridview。 Gridview有3个字段。我在另一页上有3个文本框。我已将usercontrol注册到该页面。我希望在触发另一个页面的文本框中获取Gridview字段的值,触发gridview的row命令事件。





Plz帮助...

Hi All,

I have a gridview inside an UserControl. The Gridview has 3 fields. I have 3 textboxes on another page. I have registered the usercontrol to that page. I want to get value of Gridview field in the textboxes of another page , on firing the row command event of gridview.


Plz help...

推荐答案

partial public class MyControl { // hopefully, inheritance list is left for other partial part, never repeat it

    GridView GridView = new GridView(); // keep private
    Label MyLabel = new Label(); // keep private

    //...

    public MyControl() {
        //...
        GridView.RowCommand += (sender, eventArgs) => { // add a permanent internal handler to it
           if (this.RowCommand != null)
               this.RowCommand.Invoke(this.GridView, new GridViewCommandEventArgs(/* ... */));
        }; // GridView.RowCommand
    } //MyControl

    public Color MyLabelBackColor { get { return MyLabel.BackColor; } set { MyLabel.BackColor = value; } } // very simple

    public event System.EventHandler<GridViewCommandEventArgs> RowCommand; // not as simple, see the constructor

} // class MyControl





有想法吗?







在很多情况下,你需要做一个向前步骤并重新打包在不同的事件参数类中向用户控件的用户公开的事件的事件参数,您可以从 System.EventArgs 或其他最合适的子类事件参数类型。问题是:如果您假设用户需要访问网格视图实例来实现偶数处理程序,则唯一的参考是 sender 参数。这不是字符串输入,需要类型大小写,此外,它还公开了一个私有用户控件成员。因此,您可以使用基于您自己的事件args类型的(通用)事件类型,为用户提供此用户真正需要的信息。我上面显示的代码示例几乎相同,只有 / * ... * / 部分将提交一些非常有用的信息,并且事件参数类型将是不同的,定制的。



-SA



Got the idea?



In many cases, you would need to make a step forward and re-package event argument of the event exposed to the user of the user control in a different event argument class which you can subclass from System.EventArgs or other most suitable event argument type. The problem is: if you assume that the access to the instance of the grid view is needed for a user to implement the even handler, the only reference is the sender parameter. This is not a string typing, will require type case, and, besides, it exposes a private user control member. Therefore, you can use the (generic) event type based on your own event args type, to provide the user with the information this user will really need. The code sample I''ve shown above will be nearly the same, only /* ... */ part will submit some really useful information and the event argument type will be different, a customized one.

—SA


这篇关于UserControl里面的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:23