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
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
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.
Quote:
<asp:ButtonField ButtonType="Button" CommandName="Select" Text="Select" />
Re: Gridview will only select 1st record
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.
Re: Gridview will only select 1st record