Results 1 to 6 of 6

Thread: Gridview will only select 1st record

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Gridview will only select 1st record

    Hello all,

    I have a gridview which is bound to a sqldtatasource. The gridview has 3 columns and a select button. The data in the gridview pulls up just fine when I run the application and the first record is selected.

    However when I select one of the other records, the gridview will not select it. The postback occurs and it remains on the first record. Here is code for my gridview and the sqldatasource:

    Code:
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                            AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
                            DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" ForeColor="#333333" 
                            GridLines="None" SelectedIndex="0" Width="100%">
                            <AlternatingRowStyle BackColor="White" />
                            <Columns>
                                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
                                    InsertVisible="False" ReadOnly="True" SortExpression="CustomerID" 
                                    Visible="False" />
                                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                                <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
                                <asp:ButtonField ButtonType="Button" Text="Select" />
                            </Columns>
                            <EditRowStyle BackColor="#2461BF" />
                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#EFF3FB" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#F5F7FB" />
                            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                            <SortedDescendingCellStyle BackColor="#E9EBEF" />
                            <SortedDescendingHeaderStyle BackColor="#4870BE" />
                        </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:TechSupportConnectionString %>" 
                            SelectCommand="SELECT [CustomerID], [Name], [City], [State] FROM [Customers] ORDER BY [Name]">
                        </asp:SqlDataSource>
    Can anyone see what I may be missing?

    Thanks,

    Strick

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Gridview will only select 1st record

    Hello,

    Do you have any server side code? Or is it all done through your ASPX markup?

    For instance, where is the DataBinding happening?

    Gary

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Gridview will only select 1st record

    Either specify the CommandName argument of the ButtonField to indicate which action you want the GridView to process or handle the processing yourself in the GridView_RowCommand event.


    <asp:ButtonField ButtonType="Button" CommandName="Select" Text="Select" />

  4. #4

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Gridview will only select 1st record

    or this

    http://msdn.microsoft.com/en-us/libr...=VS.80%29.aspx

    All these methods basically generate/execute the same code at run time.

  6. #6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width