J
jeffmagill
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!!!
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<asp:ObjectDataSource ID="AcronymObjectDataSource" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetAllAcronyms"
TypeName="AcronymDataTableAdapters.acronymsTableAdapter"
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>
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!!!
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<asp:ObjectDataSource ID="AcronymObjectDataSource" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetAllAcronyms"
TypeName="AcronymDataTableAdapters.acronymsTableAdapter"
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>