•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,047 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,290 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 817 | Replies: 1
![]() |
•
•
Join Date: May 2008
Posts: 23
Reputation:
Rep Power: 1
Solved Threads: 0
can anyone tell me what's wrong with my codes below..what does this error mean and how can i get rid of it...looking forward for your help..
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <h3>FormView Example</h3> <table cellspacing="10"> <tr> <td> <asp:GridView ID="ClientGridView" DataSourceID="ClientSqlDataSource" AutoGenerateColumns="false" DataKeyNames="ClientID" OnSelectedIndexChanged="ClientGridView_OnSelectedIndexChanged" RunAt="Server"> <HeaderStyle backcolor="Navy" forecolor="White" /> <Columns> <asp:ButtonField Text="Details..." HeaderText="Show<BR>Details" CommandName="Select"/> <asp:BoundField DataField="ClientName" HeaderText="Client Name"/> <asp:BoundField DataField="Address" HeaderText="Address"/> <asp:BoundField DataField="ContactPerson" HeaderText="Contact Person"/> </Columns> </asp:GridView> </td> <td valign="top"> <asp:FormView ID="ClientFormView" DataSourceID="ClientSqlDataSource" DataKeyNames="ClientID" Gridlines="Both" OnItemUpdated="ClientFormView_ItemUpdated" OnItemDeleted="ClientFormView_ItemDeleted" RunAt="server"> <HeaderStyle backcolor="Navy" forecolor="White"/> <RowStyle backcolor="White"/> <EditRowStyle backcolor="LightCyan"/> <ItemTemplate> <table> <tr><td align="right"><b>Client ID:</b></td><td><%# Eval("ClientId") %></td></tr> <tr><td align="right"><b>Client Name:</b></td> <td><%# Eval("ClientName") %></td></tr> <tr><td align="right"><b>Address:</b></td> <td><%# Eval("Address") %></td></tr> <tr><td align="right"><b>Contact Person:</b></td> <td><%# Eval("ContactPerson") %></td></tr> <tr><td align="right"><b>Telephone No.:</b></td> <td><%# Eval("TelNo") %></td></tr> <tr><td align="right"><b>Email:</b></td> <td><%# Eval("Email") %></td></tr> <tr> <td colspan="2"> <asp:LinkButton ID="EditButton" Text="Edit" CommandName="Edit" RunAt="server"/> <asp:LinkButton ID="NewButton" Text="New" CommandName="New" RunAt="server"/> <asp:LinkButton ID="DeleteButton" Text="Delete" CommandName="Delete" RunAt="server"/> </td> </tr> </table> </ItemTemplate> <EditItemTemplate> <table> <tr><td align="right"><b>User:</b></td> <td><asp:TextBox ID="UserTextBox" Text='<%# Bind("UserId") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Project:</b></td> <td><asp:TextBox ID="ProjectTextBox" Text='<%# Bind("ProjectId") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Client Name:</b></td> <td><asp:TextBox ID="EditClientNameTextBox" Text='<%# Bind("ClientName") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Address:</b></td> <td><asp:TextBox ID="EditAddressTextBox" Text='<%# Bind("Address") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Contact Person:</b></td> <td><asp:TextBox ID="EditContactPersonTextBox" Text='<%# Bind("ContactPerson") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Telephone Number:</b></td> <td><asp:TextBox ID="EditTelNoTextBox" Text='<%# Bind("TelNo") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Email:</b></td> <td><asp:TextBox ID="EditEmailTextBox" Text='<%# Bind("Email") %>' RunAt="Server" /></td></tr> <tr> <td colspan="2"> <asp:LinkButton ID="UpdateButton" Text="Update" CommandName="Update" RunAt="server"/> <asp:LinkButton ID="CancelUpdateButton" Text="Cancel" CommandName="Cancel" RunAt="server"/> </td> </tr> </table> </EditItemTemplate> <InsertItemTemplate> <table> <tr><td align="right"><b>User:</b></td> <td><asp:TextBox ID="UserTextBox" Text='<%# Bind("UserId") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Project:</b></td> <td><asp:TextBox ID="ProjectTextBox" Text='<%# Bind("ProjectId") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Client Name:</b></td> <td><asp:TextBox ID="EditClientNameTextBox" Text='<%# Bind("ClientName") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Address:</b></td> <td><asp:TextBox ID="EditAddressTextBox" Text='<%# Bind("Address") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Contact Person:</b></td> <td><asp:TextBox ID="EditContactPersonTextBox" Text='<%# Bind("ContactPerson") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Telephone Number:</b></td> <td><asp:TextBox ID="EditTelNoTextBox" Text='<%# Bind("TelNo") %>' RunAt="Server" /></td></tr> <tr><td align="right"><b>Email:</b></td> <td><asp:TextBox ID="EditEmailTextBox" Text='<%# Bind("Email") %>' RunAt="Server" /></td></tr> <tr> <td colspan="2"> <asp:LinkButton ID="InsertButton" Text="Insert" CommandName="Insert" RunAt="server"/> <asp:LinkButton ID="CancelInsertButton" Text="Cancel" CommandName="Cancel" RunAt="server"/> </td> </tr> </table> </InsertItemTemplate> </asp:FormView> </td> </tr> </table> <asp:sqlDataSource ID="ClientSqlDataSource" selectCommand="SELECT * FROM [Client] WHERE ([UserId]= @UserId)" InsertCommand="INSERT INTO Client(UserId, ProjectId, ClientName, Address, ContactPerson, TelNo, Email) VALUES (@ProjectId, @ClientName, @Address, @ContactPerson, @TelNo, @Email); SELECT @ClientId = SCOPE_IDENTITY()" UpdateCommand="UPDATE Client SET UserId=@UserId, ProjectId=@ProjectId, ClientName=@ClientName, Address=@Address, ContactPerson=@ContactPerson, TelNo=@TelNo, Email=@Email WHERE ClientId=@ClientId" DeleteCommand="DELETE Client WHERE ClientId=@ClientId" connectionstring="<%$ ConnectionStrings:TrialConnectionString %>" RunAt="server" oninserted="ClientqlDataSource_Inserted"> <SelectParameters> <asp:Parameter Name="ClientId" Type="Int32" DefaultValue="0" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="ClientId" Direction="Output" Type="Int32" DefaultValue="0" /> </InsertParameters> </asp:sqlDataSource> </form> </body> </html> protected void ClientGridView_OnSelectedIndexChanged(object sender, EventArgs e) { ClientSqlDataSource.SelectParameters["ClientId"].DefaultValue = ClientGridView.SelectedValue.ToString(); ClientFormView.DataBind(); } protected void ClientFormView_ItemUpdated(object sender, FormViewUpdatedEventArgs e) { ClientGridView.DataBind(); } protected void ClientFormView_ItemDeleted(object sender, FormViewDeletedEventArgs e) { ClientGridView.DataBind(); } protected void ClientqlDataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e) { System.Data.Common.DbCommand command = e.Command; ClientSqlDataSource.SelectParameters["ClientId"].DefaultValue = command.Parameters["@ClientId"].Value.ToString(); ClientGridView.DataBind(); ClientFormView.DataBind(); }
Last edited by peter_budo : Jun 4th, 2008 at 3:31 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,123
Reputation:
Rep Power: 3
Solved Threads: 47
Hi there fayenot, could you please post the exact error message? I have come across this one before myself I think. Also please use code tags
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
Similar Threads
- delete command does not work (ASP.NET)
- Scalar variable Error (ASP.NET)
- gridview update error (ASP.NET)
- Object reference not set to an instance of an object (ASP.NET)
- modify script (Perl)
Other Threads in the ASP.NET Forum
- Previous Thread: Remote sql database
- Next Thread: Save Data in Database , Syntax error



Linear Mode