|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Server Control to manipulate GridViewfile. I am now trying to encapsulate all of this into a self contained WebControl that basically behaves like an image button that when it is clicked the export is performed. I am not completely sure if the best approach is to define the control as a PostBackEventHandler, but I created a WebControl defined as follows: [ToolboxData("<{0}:GridViewExportButton runat=server></ {0}:GridViewExportButton>")] public class GridViewExportButton : WebControl, IPostBackEventHandler protected override HtmlTextWriterTag TagKey { get { return HtmlTextWriterTag.Input; } } protected override void AddAttributesToRender(HtmlTextWriter writer) { writer.AddAttribute(HtmlTextWriterAttribute.Type, "image"); writer.AddAttribute(HtmlTextWriterAttribute.Name, base.UniqueID); writer.AddAttribute(HtmlTextWriterAttribute.Src, this.ImageURL); base.AddAttributesToRender(writer); } My first problem has to do with being able to link the correct gridView to the control from the properties. I tried the following: [Bindable(true)] public GridView Grid { get { return (GridView)ViewState["Grid"]; } set { ViewState["Grid"] = value; } } This works very well in the designer since it shows a dropdownbox that allows me to assign one of the existing gridviews on the page to the control. However, I get the following error when it is interpreted: Cannot create an object of type GridView from it string representation. <cc1:GridViewExportButton ID="GridViewExportButton1" runat="server" Grid="GridView1" OnClick="GridViewExportButton1_Click" /> My second problem has to do with the postback handler, when the user clicks the control I need to execute server code that use the gridView object. Thanks, Jeronimo Bertran Hi Jeronimo,
Thank you for posting. Regarding on the the custom server control for exporting gridview question, I think you can develop a custom composite control which include a certain linkbutton as inner nested control and in the linkbutton's postback event do the gridview exporting work. Also, as for how to reference the GridView in our custom control, I suggest you consider using the controlID to reference GridView on the page. At runtime, our custom Control can use Page or other container control's FindControl method to locate the GridView we want to export. Also, this require that the GridView is either in the page's top level control collection or within the same Namingcontainer of our custom control, otherwise, it'll be very difficult to locate the GridView from our custom control through FindControl. Hope this helps. Regards, Steven Cheng Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) You're welcome Jeronimo,
Please feel free to post here when you need any assistance. Regards, Steven Cheng Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Access data in ObjectDataSource
no FormView for create/insert page Datagrid custom paging always loads page 1 Validation inside composite controls for ASP .NET 2.0 Datagrid cancel command does not work when adding new record custom button/link in detailsview commandfield section How to set default values for fields in detailsview problem traping event in child control must click button twice for event to fire style question |
|||||||||||||||||||||||