Solved

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

Posted on 2013-11-24
1
464 Views
Last Modified: 2013-12-11
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">
    <Columns>
        <asp:TemplateField ItemStyle-CssClass="styleSmCol5" HeaderStyle-CssClass="styleMedColHdrCtr5" ItemStyle-Wrap="false" HeaderText="Date Posted">
            <ItemTemplate>
                <asp:LinkButton ID="lbMyLinkButton" runat="server" Text='<%# Eval("Date Posted")%>' OnClick="lbMyLinkButton_Click()" CssClass="EditSizeTxt"></asp:LinkButton>
            </ItemTemplate> 
        </asp:TemplateField>

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

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

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!
0
Comment
Question by:EchoBinary
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39674511
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
http://msdn.microsoft.com/en-us/library/yhzc935f.ASPX
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question