Solved

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

Posted on 2013-11-24
1
460 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get id from json Data with NewtonSoft 3 34
consuming an asmx web service in winforms application 3 25
Device Location 4 13
Need a starter for ETL protocol? 4 43
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

17 Experts available now in Live!

Get 1:1 Help Now