Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView & DetailsView - Wrong Record Being Sent Over

Reply
Thread Tools

GridView & DetailsView - Wrong Record Being Sent Over

 
 
jeffmagill@gmail.com
Guest
Posts: n/a
 
      05-10-2006
Hi Everybody,

I'm really hoping that someone can help me out because I have spent too
much time on this project already!

Basically, I have a DetailsView that handles all the Edits for a
GridView - each row has an edit button and clicking on this should
trigger that record to be loaded into the DetailsView for editing. The
problem is that the record never gets loaded into the DetailsView.
Instead, the DetailsView always and only contains the first record of
the table. My guess is that something is wrong with the
CommandName='Select' column in the GridView, but I'm hopeless.

Both objects share the same asp:ObjectDataSource,
AcronymObjectDataSource, which pulls from a TableAdapter which accesses
a SQL database.

Here's the relevant code that I can think of with some nice 'X'
dividers to separate the objects. Obviously they arent in the original
aspx file but this is basically how the aspx file appears.

By the way, the DB is
id int, (primary key)
term varchar 20,
definition varchar 500,
featured bit

Thanks in advance!!!

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX

<asp:GridView ID="AllAcronymsGridView" runat="server"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="AcronymObjectDataSource" PageSize="33">
<Columns>
<asp:BoundField DataField="term" HeaderText="Term"
SortExpression="term" />
<asp:BoundField DataField="definition" HeaderText="Definition"
SortExpression="definition" />
<asp:CheckBoxField DataField="featured" HeaderText="Featured"
SortExpression="featured" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnSelect" runat="server"
CausesValidation="False" CommandName="Select" Text="Edit"
OnClick="btnSelect_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server"
CausesValidation="False" CommandName="Delete" Text="Delete"
OnClientClick="return confirm('Are you sure you want to delete this
record?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True" SortExpression="id" />
</Columns>
<PagerSettings Position="TopAndBottom" />
</asp:GridView>

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX

<aspetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataKeyNames="id"
DataSourceID="AcronymObjectDataSource" Height="50px" Width="100%"
DefaultMode="Edit" CellPadding="5" GridLines="None">

<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"
Width="100px" />
<Fields>
<asp:TemplateField HeaderText="Term" SortExpression="term">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"
Width="100px" />
<ItemTemplate>
<asp:Label ID="TermLabel" runat="server" Text='<%#
Bind("term") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="term_tb" runat="server" Text='<%#
Bind("term") %>' />
<asp:RequiredFieldValidator ID="valTermTextBox"
ControlToValidate="term_tb" runat="server" Display="dynamic" Text="<br
/>Term is a required field"
CssClass="error"></asp:RequiredFieldValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:textbox ID="term_tb" runat="server" Text='<%#
Bind("term") %>' />
<asp:RequiredFieldValidator ID="valTermTextBox"
ControlToValidate="term_tb" runat="server" Display="dynamic" Text="<br
/>Term is a required field"
CssClass="error"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Name:" SortExpression="term">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"
Width="100px" />

<ItemTemplate>
<asp:Label ID="DefLabel" runat="server" Text='<%#
Bind("definition") %>'></asp:Label>
</ItemTemplate>

<EditItemTemplate>
<asp:TextBox ID="def_tb" runat="server" Text='<%#
Bind("definition") %>'></asp:TextBox><asp:RequiredFieldValidator
ID="valDefTextBox" ControlToValidate="def_tb" runat="server"
Display="dynamic" Text="<br />Definition is a required field"
CssClass="error"></asp:RequiredFieldValidator>
</EditItemTemplate>

<InsertItemTemplate>
<asp:TextBox ID="def_tb" runat="server" Text='<%#
Bind("definition") %>'></asp:TextBox><asp:RequiredFieldValidator
ID="valDefTextBox" ControlToValidate="def_tb" runat="server"
Display="dynamic" Text="<br />Definition is a required field"
CssClass="error"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>

<asp:CheckBoxField DataField="featured"
HeaderText="Featured:" SortExpression="featured" />

<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:Button ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update" Text="Update This
Record"></asp:Button>
<asp:Button ID="CancelUpdateButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel"
OnClick="CancelUpdateButton_Click"></asp:Button>
</EditItemTemplate>

<InsertItemTemplate>
<asp:Button ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert" Text="Insert New
Record"></asp:Button>
<asp:Button ID="CancelInsertButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel"
OnClick="CancelInsertButton_Click"></asp:Button>
</InsertItemTemplate>
</asp:TemplateField>

</Fields>
</aspetailsView>

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXX

<asp:ObjectDataSource ID="AcronymObjectDataSource" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetAllAcronyms"
TypeName="AcronymDataTableAdapters.acronymsTableAd apter"
UpdateMethod="Update">
<DeleteParameters>
<asparameter Name="Original_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="term" Type="String" />
<asparameter Name="definition" Type="String" />
<asparameter Name="featured" Type="Boolean" />
<asparameter Name="Original_id" Type="Int32" />
<asparameter Name="id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="term" Type="String" />
<asparameter Name="definition" Type="String" />
<asparameter Name="featured" Type="Boolean" />
</InsertParameters>
</asp:ObjectDataSource>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Gridview and Detailsview "New" record Giorgio ASP .Net 1 03-15-2006 11:33 AM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM
How to insert a new record in detailsview when there are no record Frits van Soldt ASP .Net Web Controls 2 11-17-2005 09:18 AM
How can I snoop on data being sent from program over net Frank Computer Support 3 01-24-2004 01:21 PM



Advertisments