-
March 17th, 2011, 09:25 PM
#1
sqldatasource not filling in web controls
Hi
I have a very simple example of text boxes trying to get data from sqldatasource as below;
<%@ Page Language="C#" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.Update();
}
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
}
</script>
<html>
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtApplicantID" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="txtSurname" runat="server"></asp:TextBox>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT [ApplicantID], [last_name] FROM [Applicants]" UpdateCommand="UPDATE [Applicants] SET [last_name] = @last_name WHERE [ApplicantID] = @ApplicantID">
<UpdateParameters>
<asp:ControlParameter Name="ApplicantID" Type="Int32" ControlID="txtApplicantID"
PropertyName="Text" />
<asp:ControlParameter Name="last_name" Type="String" ControlID="txtSurname" PropertyName="Text" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
</body>
</html>
Problem is; the two text box controls neither get the data from nor update it back to the backend table. What could be wrong with such a simple code?
The backend table is defined as below.
CREATE TABLE [dbo].[Applicants](
[ApplicantID] [int] IDENTITY(1,1) NOT NULL,
[last_name] [nvarchar](255) NULL,
CONSTRAINT [PK_Applicants] PRIMARY KEY CLUSTERED
(
[ApplicantID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Any help to fix the two way data update issue would be appreciated.
Many Thanks
Regards
-
March 18th, 2011, 01:50 AM
#2
Re: sqldatasource not filling in web controls
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|