From: JJ297 on 20 Jul 2010 09:49 Here's my gridview I'm working with... TrainID Location TrainDate Times FullName Edit 6 ClassA 7/26/2010 9:00am Lisa Jones (want to add) Edit 7 ClassB 7/26/2010 11:00am Edit 8 ClassC 7/26/2010 2:00am I want to click on Edit and be able to enter Lisa Jones in the fullname field. When I update it I want this info to go into this table: TraineeInfo Table TraineeID PK, int, not null, TrainID int FK, int, not null, FullName varchar (75) Here's my gridview with the Eval and Bind added to capture the fullname: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True" DataKeyNames="TrainID" DataSourceID="TSRPTraining" EnableModelValidation="True"> <Columns> <asp:BoundField DataField="TrainID" HeaderText="TrainID" InsertVisible="False" ReadOnly="True" SortExpression="TrainID" /> <asp:BoundField DataField="Location" HeaderText="Location" ReadOnly="True" SortExpression="Location" /> <asp:BoundField DataField="TrainDate" HeaderText="TrainDate" ReadOnly="True" SortExpression="TrainDate" /> <asp:BoundField DataField="Times" HeaderText="Times" ReadOnly="True" SortExpression="Times" /> <asp:TemplateField HeaderText="Full Name"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("fullname") %>' /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("fullname") %>' /> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> When I try to run it I'm getting this error message on the ItemTemplate: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'fullname'. I created this stored procedure to update what's in the gridview: alter procedure [dbo].[AddTraineeInfo] --'6', 'Linda Barnet' @trainid int, @fullname varchar(75) AS update TraineeInfo set [fullname] = @fullname Where TrainID=(a)Trainid When I ran this in sql query and inserted trainid 6 and the name Linda Barnet it updated all of the trainid = 6 info TraineeID TrainID FullName 4 6 Linda Barnet 5 7 Barry Williams 6 6 Linda Barnet How do I get it to update/add Lisa Jones and place into the TraineeInfo table as this? TraineeID TrainID FullName 4 6 Linda Barnet 5 7 Barry Williams 6 6 Linda Barnet 7 6 Lisa Jones Here's the scripts for create table and insert CREATE TABLE [dbo].[TraineeInfo]( [TraineeID] [int] IDENTITY(1,1) NOT NULL, [TrainID] [int] NOT NULL, [FullName] [varchar](75) NULL, [Componet] [varchar](75) NULL, CONSTRAINT [PK_Trainee] PRIMARY KEY CLUSTERED ( [TraineeID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[TraineeInfo] WITH CHECK ADD CONSTRAINT [FK_Trainee_TraineeID] FOREIGN KEY([TrainID]) REFERENCES [dbo].[TSRPTraining] ([TrainID]) GO ALTER TABLE [dbo].[TraineeInfo] CHECK CONSTRAINT [FK_Trainee_TraineeID] INSERT INTO [TSRPTraining].[dbo].[TraineeInfo] ([TrainID] ,[FullName] ,[Componet]) VALUES (<TrainID, int,> ,<FullName, varchar(75),> ,<Componet, varchar(75),>)
|
Pages: 1 Prev: Connector/Net Next: how to bind an query to a gridview programmatically? |