GridView - using different datasources for select and edit templates

Last post 05-21-2007 5:49 AM by dj_kopral. 3 replies.

Sort Posts:

  • Confused [*-)] GridView - using different datasources for select and edit templates

    11-05-2006, 4:36 AM

    I've been reading this forum and MSDN library for several hours now, so please re-direct me if this has been answered elsewhere and I've missed the post. 

    For readability, I want to show names in the form 'FirstName LastName' as a single field in a GridView, but when I edit a row, I want to then display them as separate fields 'Firstname', 'Lastname'.  The concatenation to a single field is working well with a stored function, and the datasource I'm using is a SQLDataSource using stored procedures - both in SQLExpress.  Later I plan to use a TableAdapter, but not until I can get the basic functionality behaving correctly.

    Should I:

    1. include the fullName as an extra field in the datasource (display it for the select while hiding the firstName and lastName fields, then hide the fullName field while displaying firstName and lastName for edit & insert) ?
    2. find a way to use separate datasources for the edit and insert templates ?

    Has anyone been able to make either of these options work?  If so, have you used events to change the visibility of the fields (for option1) or the GridView datasource (for option2)??

    If you have a solution, please post enough of the event statement block for me to follow (C# preferred).

    TIA

    best viewed at 1024*768, and with a computer
  • Re: GridView - using different datasources for select and edit templates

    11-05-2006, 8:24 PM
    • Loading...
    • imran.nathani
    • Joined on 04-07-2006, 9:32 AM
    • Toronto,Canada
    • Posts 836

    let me get this correct in the select mode you want the firstname & lastname together.but in the edit mode u want them seperately?

    if yes....this is a display issue ....no need to use multiple datasources...you could just use an extra label in the item template of the firstname & delete the label in the edit item template of the last name coulmn.

  • Re: GridView - using different datasources for select and edit templates

    05-21-2007, 2:40 AM
    • Loading...
    • iumer
    • Joined on 12-18-2006, 12:08 PM
    • Posts 115

    i have some issue like...

    i m binding grid on pageload and  first i add column and then i bind it , gridview showd data prperly, but as i click on grid ( i made my gridclickable) my grid datasource become null, and also column.count to zero, :S should i need to bind it again and again for each post back? also if i click any other control that do postback , gridview dataremain corectly... but when i click gridivew.. its shows null

    i put gridivew viewstate = true

    plz hlep me 

    Umer Khan
    Sr. Software Engineer
    Umer.Khan@systemsltd.com
    ------------------------
    Click "Mark As Answer"
    iff,It helped You
  • Re: GridView - using different datasources for select and edit templates

    05-21-2007, 5:49 AM
    • Loading...
    • dj_kopral
    • Joined on 02-07-2007, 9:59 PM
    • Posts 13

    make it like this:

                    <asp:TemplateField HeaderText="Name">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("firstname") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("firstname") %>'></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("firstname") %>'></asp:Label> -
                            <asp:Label ID="Label7" runat="server" Text='<%# Eval("lastname") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="lastname" >
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("lastname") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("lastname") %>'></asp:TextBox>
                        </InsertItemTemplate>
                    </asp:TemplateField>

    hope this help... 

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter