Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Go Back  Xtreme Visual Basic Talk > > > Gridview or DataGrid for Dynamic Listing of Data


Reply
 
Thread Tools Display Modes
  #1  
Old 11-18-2008, 11:43 PM
FacJoe FacJoe is offline
Centurion
 
Join Date: Jun 2003
Posts: 107
Default Gridview or DataGrid for Dynamic Listing of Data


Hi.

I'm currently doing a project where we need a grid to display certain data coming from a SQL database.

My problem is, I want to be able to make a dynamic grid that will do different sorts of thing upon several user inputs.

One case is when the user presses the "Edit" button of the grid, instead of editing the whole row of the grid, column 2 and column 4 of the said grid will become a drop-down list control and will retrieve another set of data from the SQL database. The other columns must remain unaffected by this "event", though.

Right now, we are using a DataGrid to achieve the said functionality, but I want to refactor the code and probably use a GridView and DataSet and DataAdapter because we're taking into consideration the loading time of the page. It takes 8 seconds to load the entire page and we wanted to reduce it to say, 2-3 seconds. The problem is, I don't know how to do it using the GridView/DataSet/DataAdapter combo while providing the same dynamic functionality it had when we used the DataGrid control.

Any input will be greatly appreciated. Thank you.
Reply With Quote
  #2  
Old 11-20-2008, 09:56 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Specify your controls in the EditDataTemplate tag which you write underneath the column that you will want edited. For a DropDownList do something like this:

Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:TemplateField HeaderText="City" SortExpression="City">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="City" DataValueField="City" SelectedValue='<%# Bind("City") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%#Bind("City") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
I ripped this example of the MSDN site but deleted a lot of stuff and bolded the section you'll find most interesting. Just know for the SelectedValue piece to work properly, you'll need a column returned from your DataSource called "City" in this case (can be anything though as long as they match). The ItemTemplate field just says what will appear when the GridView is not being edited, in this case a label. When edit is clicked the GridView will switch to the EditItemTemplate section and try to bind the DropDownList with the specified column, taken from the DataSource. It's a lot to take in but GridViews can be very powerful. This should give you a little bit of a start as to how GridViews work though...hopefully. Good luck and happy coding!
Reply With Quote
  #3  
Old 11-24-2008, 02:54 AM
RichardV RichardV is offline
Newcomer
 
Join Date: Nov 2008
Posts: 16
Default

Didn't you designed the data in an object, a specific class which holds the data? Those objects are also bindable to datagrids.
We can't tell you how to solve the datamining issue. That depends on a lot of things, for example your stored procedure or querystring.

Like Targe said, if you added edit functionality to your grid, each field (except readonly fields) will be added to the EditItemTemplate. If you don't want certain fields to expose while editing, just remove them from the EditItemTemplate (or make them invisible) and you're done.

Always remember that most data will be for showing-purpose only and a user will be editting only one row in a time. This means that you should reconsidder the definition of the page. Is it designed for showing data or for editing data. Maybe it's easier to show the editable regions in some Ajax control?

Regards,
Richard
The Netherlands
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
 
Gridview or DataGrid for Dynamic Listing of Data
Gridview or DataGrid for Dynamic Listing of Data
 
-->