Dropdownlist in ASP.net C# and mysql - c#

I have a table 'TYPE' in this table i have 2 columns as 'SKEY' AND 'CASECODE'.
'SKEY' contains text value and 'CASECODE' contains the corresponding numeric value.
I have bound the values in the column 'SKEY' to a DropdownList control in ASP.net 3.5 C#, What i want is on selection of one item in the DropdownList the corresponding value in the column 'CASECODE' should be displayed.
I have created a datasource for a dropdown list and i want to have DataTextField which is visible to the user to be a value from column SKEY and dropdownlistDataValueField to be a value from column 'casecode' but when i try to do
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource1" DataTextField="skey" DataValueField="casecode"
AppendDataBoundItems="True">
<asp:ListItem Selected="True" Value="S">Select</asp:ListItem>
</asp:DropDownList>
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'casecode'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'casecode'.
My .aspx code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>
<!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 title="orderfrm" id="form1" runat="server" onsubmit="validate()" >
<div>
<br />
<b>
<asp:Label ID="Label1" runat="server" style="font-size: x-large"
Text="Order Modify"></asp:Label>
<br />
</b>
<br />
<asp:Label ID="Label2" runat="server" style="font-weight: 700"
Text="High Court:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"
>
<asp:ListItem>Panaji</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label3" runat="server" style="font-weight: 700"
Text="Stmp/Regn.:"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Value="R">Registrer</asp:ListItem>
<asp:ListItem Value="S">Stamp</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label4" runat="server" style="font-weight: 700" Text="Type:"></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource1" DataTextField="skey" DataValueField="casecode"
AppendDataBoundItems="True">
<asp:ListItem Selected="True" Value="S">Select</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="DropDownList3" ErrorMessage="Select Case Type"
InitialValue="S">*</asp:RequiredFieldValidator>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>"
SelectCommand="SELECT testcase.casetype.skey FROM testcase.casetype">
</asp:SqlDataSource>
<asp:Label ID="Label5" runat="server" style="font-weight: 700" Text="No"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Enter Case No">*</asp:RequiredFieldValidator>
<asp:Label ID="Label6" runat="server" style="font-weight: 700" Text="Year:"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Enter Year">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Enter Valid Year"
ValidationExpression="^\d{4}$"></asp:RegularExpressionValidator>
<br />
<br />
<asp:Label ID="Label7" runat="server" style="font-weight: 700"
Text="Order Date"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Enter Date">*</asp:RequiredFieldValidator>
<asp:Label ID="Label8" runat="server" style="font-weight: 700"
Text="(dd/mm/yyyy)"></asp:Label>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Enter Valid Date"
ValidationExpression="^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$"></asp:RegularExpressionValidator>
<br />
<asp:Button ID="Button2" runat="server" style="font-weight: 700" Text="Go"
onclick="Button2_Click"/>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<br />
</div>
<cc1:Editor ID="Editor1" runat="server" AutoFocus="true" Height="200px" Width="500px" ActiveMode="Design" Font-Strikeout="false" />
<br />
<asp:ScriptManager ID="ScriptManager2"
runat="server" > </asp:ScriptManager>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Show" />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Select" />
<asp:Button ID="Button4" runat="server" onclick="Button4_Click"
Text="next page" />
</form>
</body>
</html>

The select command of your data source does not include a field named casecode:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>"
SelectCommand="SELECT testcase.casetype.skey FROM testcase.casetype">
</asp:SqlDataSource>
Probably you want to edit SelectCommand to something like this (depending on how your database looks like):
SelectCommand="SELECT testcase.casetype, testcase.casetype.skey FROM testcase.casetype"

Try binding your DataTextField and DataValueField -
dropdownlist.DataSource = <GetData>();
dropdownlistDataTextField="<SKEY column values>";
dropdownlistDataValueField="<CASECODE column values>";
dropdownlist.DataBind();

I am not entirely sure what you are asking, but dropdownlist.SelectedValue would give you the value which is the casecode in this case.

Related

Why does asp.net display table name instead of table field

im working on a project and im combining 3 tables the tables are already associated in the dbml but my problem is when i use the data list it diaplays my table names not the correct fields this is a college assignment but i have tried everything i know to do.
I've tried to combine them seperatly in sql manager in vs but im just not understanding why it isn't showing the correct thing
<form id="form1" runat="server">
<div>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="assign_6_final.DataClasses1DataContext" EntityTypeName="" Select="new (CustomerID, Name)" TableName="Customers">
</asp:LinqDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="LinqDataSource1" DataTextField="Name" DataValueField="CustomerID" OnSelectedIndexChanged="Page_Load">
</asp:DropDownList>
<asp:DataList ID="DataList1" runat="server" DataSourceID="LinqDataSource2" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnDataBinding="DataList1_SelectedIndexChanged">
<ItemTemplate>
IncidentID:
<asp:Label ID="IncidentIDLabel" runat="server" Text='<%# Eval("IncidentID") %>' />
<br />
DateOpened:
<asp:Label ID="DateOpenedLabel" runat="server" Text='<%# Eval("DateOpened") %>' />
<br />
DateClosed:
<asp:Label ID="DateClosedLabel" runat="server" Text='<%# Eval("DateClosed") %>' />
<br />
Title:
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
<br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
<br />
CustomerID:
<asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />
<br />
Technician:
<asp:Label ID="TechnicianLabel" runat="server" Text='<%# Eval("Technician") %>' />
<br />
Product:
<asp:Label ID="ProductLabel" runat="server" Text='<%# Eval("Product") %>' />
<br />
<br />
<br />
</ItemTemplate>
</asp:DataList>
</div>
<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="assign_6_final.DataClasses1DataContext" EntityTypeName="" Select="new (IncidentID, DateOpened, DateClosed, Title, Description, CustomerID, Technician, Product)" TableName="Incidents" Where="CustomerID = #CustomerID">
<WhereParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CustomerID" PropertyName="SelectedValue" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:EntityDataSource ID="EntityDataSource1" runat="server">
</asp:EntityDataSource>
</form>
</body>
the outcome i expected was that the last 2 items the product and technician would output correctly but they haven't and im kind of lost my teacher said this is a common problem in asp but ive never seen it
Try using the following and so forth:
<%# DataBinder.Eval(Container.DataItem,"CustomerID") %>

Passing Eval value to C# method for shopping cart

I am creating a shopping cart web app for my class. When the user clicks on the add to cart button, I want to pass the value of the ID of each specific product to a separate method in the code behind. Not sure if my syntax is off or if this just wont work. Here is my mark up:
<asp:Button ID="AddToCart" CommandName="Add"
OnClientClick ='<%# ListView1_AddToCart(Eval("ID"))%>'
CssClass ="Button" runat="server" Text="Add to Cart" />
Here is my code behind:
public void ListView1_AddToCart(string CatID)
{cart.AddToCart(CatID);}
I keep getting various issues, but this gives me the following error:
The best overloaded method match for 'OurCats_GrumpyCats.ListView1_AddToCart(string)'
has some invalid arguments.
How can I resolve this? Is there any better way?
EDIT: Here is my mark up
<%# Page Title="All Cats" Language="C#" MasterPageFile="~/MasterPage/Layout.master" AutoEventWireup="true" CodeFile="AllCats.aspx.cs" Inherits="OurCats_GrumpyCats" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<h1>Meet all of our kittens!</h1>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource2">
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Price:
<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
<br />
Imgu:
<asp:TextBox ID="ImguTextBox" runat="server" Text='<%# Bind("Img") %>' />
<br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
<br />
<br />
</span>
</InsertItemTemplate>
<ItemTemplate>
<table class ="Table" style="border-style: solid; ">
<tr>
<td >
<a href ="Details.aspx?ID=<%# Eval("ID")%>">
<img src="../Images/<%# Eval("Img") %>" width ="200" />
</a>
</td>
<td style="width:700px; margin-left: 100px">
<asp:Label ID="Label1" runat="server" Text="Name: "></asp:Label><asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
<asp:Textbox ID="CatID" runat="server" Visible="false" Text='<%# Eval("ID")%>'></asp:Textbox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Price: $"></asp:Label><asp:Label ID="PriceLabel" runat="server" Text= '<%# Eval("Price") %>'/>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Description: "></asp:Label><asp:Label ID="DescriptionLabel" runat="server" Text= '<%# Eval("Description") %>' />
<br />
<br />
<asp:Button ID="AddToCart" CommandName="Add" OnClientClick='<%# "AddToCart(" +Eval("ID") + " );" %>' CssClass ="Button" runat="server" Text="Add to Cart" />
</td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style =" margin-left :30px;">
<span runat="server" id="itemPlaceholder" />
</div>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:420_Project_GLConnectionString1 %>" SelectCommand="SELECT * FROM [OurCats]">
</asp:SqlDataSource>
</asp:Content>
try below code
<asp:Button ID="AddToCart" CommandName="Add"
OnClientClick ='<%# ListView1_AddToCart((string)Eval("ID"))%>'
CssClass ="Button" runat="server" Text="Add to Cart" />
OnClientClick ='<%# "ListView1_AddToCart(" +Eval("ID") + " );" %>'

Can't access dropdownlist in code behind

I am new and learning ASP.Net webforms. I have a DropDownList here:
<asp:DropDownList id="DropDownList1" runat="server">
</asp:DropDownList>
I am trying to access it by typing "DropDownList1" in my Page_Load event. but Intellisense doesn't show DropDownList1. So I assume I am doing something wrong but don't understand what is wrong.
I'm trying to access DropDownList so I can programmatically populate it with numbers.
EDIT: if my dropdownlist is inside another control, then I'm not seeing it:
<%# Page Title="Register" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Fake_Coupon_Site.Account.Register" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<hgroup class="title">
<h1><%: Title %>.</h1>
<h2>Use the form below to create a new account.</h2>
<h3>Suggested Readingfor <%= DateTime.Now.ToString("dddd, MMMM dd")%></h3>
</hgroup>
<asp:CreateUserWizard runat="server" ID="RegisterUser" ViewStateMode="Disabled" OnCreatedUser="RegisterUser_CreatedUser">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="wizardStepPlaceholder" />
<asp:PlaceHolder runat="server" ID="navigationPlaceholder" />
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep runat="server" ID="RegisterUserWizardStep">
<ContentTemplate>
<p class="message-info">
Passwords are required to be a minimum of <%: Membership.MinRequiredPasswordLength %> characters in length.
</p>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="ErrorMessage" />
</p>
<fieldset>
<legend>Registration Form</legend>
<ol>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">User name</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RegularExpressionValidator runat="server" ControlToValidate="UserName" ValidationExpression=".{3,50}"
CssClass="field-validation-error" ErrorMessage="The user name field needs to be 3 to 50 characters." />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" style="margin-left:-325px;"
CssClass="field-validation-error" ErrorMessage="The user name field is required." />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Email">Email address</asp:Label>
<asp:TextBox runat="server" ID="Email" TextMode="Email" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Email"
CssClass="field-validation-error" ErrorMessage="The email address field is required." />
</li>
<li>
<asp:DropDownList id="DropDownList1" runat="server">
</asp:DropDownList>
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password"
CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="ConfirmPassword">Confirm password</asp:Label>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The confirm password field is required." />
<asp:CompareValidator runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The password and confirmation password do not match." />
</li>
</ol>
<asp:Button runat="server" CommandName="MoveNext" Text="Register" />
</fieldset>
</ContentTemplate>
<CustomNavigationTemplate />
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</asp:Content>
What you need is this:
DropDownList DropDownList1 = (DropDownList)RegisterUserWizardStep.ContentTemplateContainer.FindControl("DropDownList1");
Since it's in a different NamingContainer than the Page you need to use FindControl to get it:
DropDownList DropDownList1= (DropDownList)RegisterUserWizardStep.FindControl("DropDownList1");

Trying to bind data from DropDownList in ListView

I am trying to bind data from DropDownList in ListView in EditItemTemplate but it didn't work.
Code:
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("type")%>'>
<asp:ListItem Text="Fatwa" Value="1"></asp:ListItem>
<asp:ListItem Text="Interviewer" Value="2"></asp:ListItem>
<asp:ListItem Text="Programs" Value="3"></asp:ListItem>
</asp:DropDownList>
Here is sample of concept you can use:
<EditItemTemplate>
<asp:Label ID="DataLabel" runat="server" Text="<% $resources:AppResource,UserData %>"
CssClass="OneColumnTitleLabel"></asp:Label>
<br />
<br />
<asp:Label ID="EmailLabel" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Email + ":" %>'></asp:Label><br />
<asp:TextBox ID="EmailTextBox" runat="server" CssClass="RightColumnText" Text='<%# Eval("Email") %>'
ReadOnly="true"></asp:TextBox>
<br />
<asp:Label ID="LanguageLabel" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Language + ":" %>'></asp:Label><br />
<asp:DropDownList ID="LanguageDropDown" runat="server" CssClass="RightColumnDropDown"
DataSourceID="LanguageDataSource" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("LanguageId") %>'
AppendDataBoundItems="True">
<asp:ListItem Value="" Text="" Selected="True">
</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label2" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Company + ":" %>'></asp:Label><br />
<asp:TextBox ID="CompanyTextBox" runat="server" CssClass="RightColumnText" Text='<%# Bind("Company") %>'></asp:TextBox>
<br />
<asp:Label ID="PhoneLabel" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Phone + ":" %>'></asp:Label><br />
<asp:TextBox ID="PhoneTextBox" runat="server" CssClass="RightColumnText" Text='<%# Bind("Phone") %>'></asp:TextBox>
<br />
<asp:Button ID="UpdateUserData" runat="server" Text='<%# Resources.AppResource.Save %>'
CssClass="Button" CommandName="Update" CausesValidation="true" />
</EditItemTemplate>
Take notice on LanguageDropDown (LanguageId is binded back to listview). This dropdown is binded to datasource like this one:
<asp:ObjectDataSource ID="LanguageDataSource" runat="server" SelectMethod="GetLanguages"
TypeName="GP.Solutions.Services.LanguageManager"></asp:ObjectDataSource>
This is how you can bind dropdown inside listview.
My code working well but I forgot to type DataKeyNames in listview :D
<asp:ListView ID="TodayOrdersList" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID">

Problem with Validation Control in formview ASP.NET C#

I'm having some problem with validation control in formview. I could add a validation control inside a formview control it was working fine until I tried to group them using validationgroups. Also if I dont enter a value the program still allow to add it in the database. Could someone help me point out the problem or error in my program? Here's the Insert statement I've made.
<InsertItemTemplate>
Book ID:
<asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
<asp:RequiredFieldValidator ID="RequesFieldValidator1" runat="server" ErrorMessage="* Required" ControlToValidate="bookidTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator" runat="server" Display="Dynamic" ControlToValidate="bookidTextBox" ValidationExpression="^([\S\s]{13,13})$" ErrorMessage="Value must be at least 13 characters long">
</asp:RegularExpressionValidator>
<br />
Title:
<asp:TextBox ID="booktitleTextBox" runat="server"
Text='<%# Bind("booktitle") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* Required" ControlToValidate="booktitleTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Author's lastname:
<asp:TextBox ID="lastnameTextBox" runat="server"
Text='<%# Bind("lastname") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="* Required" ControlToValidate="lastnameTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Author's firstname:
<asp:TextBox ID="firstnameTextBox" runat="server"
Text='<%# Bind("firstname") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="* Required" ControlToValidate="firstnameTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Description:
<asp:TextBox ID="descriptionTextBox" runat="server"
Text='<%# Bind("description") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="* Required" ControlToValidate="descriptionTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Category:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="categoryDataSource" DataTextField="name"
DataValueField="categoryid" SelectedValue='<%# Bind("categoryid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="categoryDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [categoryid], [name] FROM [TblCategory]">
</asp:SqlDataSource>
<br />
Date added:
<asp:TextBox ID="dateaddedTextBox" runat="server"
Text='<%# Bind("dateadded") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="* Required" ControlToValidate="dateaddedTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Status:
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="statusDataSource" DataTextField="statusname"
DataValueField="statusid" SelectedValue='<%# Bind("statusid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="statusDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [statusid], [statusname] FROM [BookStatus]">
</asp:SqlDataSource>
<br />
Quantity:
<asp:TextBox ID="quantityTextBox" runat="server"
Text='<%# Bind("quantity") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="* Required" ControlToValidate="quantityTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Add" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
Any help would be much appreciated ;)
Thanks in advance.
You have to set ValidationGroup="InsertBook" as you have set Validation group to your validation.
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Add" ValidationGroup="InsertBook" />

Categories

Resources