[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Emulate <Colunms>......</Columns> for a GridView inside a UserControl; but control it from outside the UserControl?

Ok, so my task is to take a bunch of old .asp pages and translate them into ASP.NET pages. the meat & potatoes of this task is to take a lot of the data display tables and turn them into <asp:Panel>'s with <asp:Gridview>'s inside of them. Aside from the custom <Column>'s & the specific setup of the sproc & (possible) parameters in the code behind - this is leading to a lot of repetitive markup/code (C#):
1) method for getting the dataset (sproc in here)
2) method for binding the dataset to the gridview (if tables/rows > 0)
3) gridview_PageIndexChanging
4) (IF there is a linkbutton column for "drilldown") linkbutton_click which calls a setPanelView() method
5) method setPanelView: Show/Hide the panels ("drill down" through the Gridviews) based on which linkbuttons have been clicked
--- only one such "entity"/<asp:Panel> can be visible at a time

I'd like to condense all this into a UserControl - but unfortunately I have little to no experience with UCs and I am in desperate need of some specific help a.s.a.p.
(deadlines, ack!)

The queries would be different per instance of the control. They will all be stored procedures, sometimes the sprocs will have parameters passed based on information passed by another UC instance where a linkbutton was clicked.

Given that the queries are different obviously this means that the columns will be different per instance of the usercontrol. Is it possible to do something like this?:

<uc1:GridViewPanel ID="gvpViewDataByDate" runat="server">
        <asp:TemplateField ItemStyle-CssClass="styleSmCol5" HeaderStyle-CssClass="styleMedColHdrCtr5" ItemStyle-Wrap="false" HeaderText="Date Posted">
                <asp:LinkButton ID="lbMyLinkButton" runat="server" Text='<%# Eval("Date Posted")%>' OnClick="lbMyLinkButton_Click()" CssClass="EditSizeTxt"></asp:LinkButton>

        <asp:TemplateField ItemStyle-CssClass="styleSmCol5" HeaderStyle-CssClass="styleMedColHdrCtr5" ItemStyle-Wrap="false" HeaderText="DIC">
                <asp:LinkButton ID="lbDIC" runat="server" Text='<%# Eval("DIC")%>' OnClick="lbDIC_Click" CssClass="EditSizeTxt"></asp:LinkButton>

        <asp:TemplateField ItemStyle-CssClass="styleSmCol5Rt" HeaderStyle-CssClass="styleMedColHdrCtr5" ItemStyle-Wrap="false" HeaderText="Record Count">
                <asp:Label ID="lblRecordCount" runat="server" Text='<%# Eval("Record Count")%>' CssClass="EditSizeTxt"></asp:Label>

Open in new window

Clearly that isn't how its done (is it?) But something like that or as close to that would be wonderful.  Either in the external markup (*as above), or in the external codebehind I need to be able to intelligently add the column/ItemTemplate controls appropriate to that specific instance of that data (e.g. - label, linkbutton, etc..), nothing as complicated as a dropdown (or that's for another question)

More or less simply put, the GridView inside the UC needs to have AutoGenerateColumns=False so that the GridView can somehow (whether in the markup or the codebehind) general the appropriate Columns, ItemTemplates, and in-Grid controls for the query that is unique to any instance of the UC...
Icing on the cake would be a way to input text and filter the dataset: e.g. search results!

Please, any help would be greatly appreciated! Thank you!
1 Solution
Bob LearnedCommented:
I like the design experience better when working with custom controls, since you can have design-time HTML.  User Controls behave a little different from Custom Controls.

Walkthrough: Developing and Using a Custom Web Server Control

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now