Link to home
Start Free TrialLog in
Avatar of EchoBinary
EchoBinaryFlag for United States of America

asked on

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">
    <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!
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial