Solved

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

Posted on 2013-11-24
1
455 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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now