DetailsView Does not Carry Some Fields over to DetailsViewUpdatedEventArgs and DetailsViewInsertedEventArgs - asp.net

I have a few fields using asp:TemplateField. The code sample for user name and password is below -
<asp:TemplateField HeaderText="User Name" SortExpression="User_Name">
<EditItemTemplate>
<ISEP:PFTextBox ID="User_NameControl" runat="server" Text='<%# Bind("User_Name") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_NameRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:CustomValidator id="CustomValidatorUserNameExisting" ControlToValidate="User_NameControl" ClientValidationFunction="UserNameExistingValidate"
Display="Static" ErrorMessage="User Name already exists. Please enter a different user name." ForeColor="red" runat="server" Enabled="false"/>
<asp:RequiredFieldValidator
ID="User_NameControlRequiredFieldValidator" runat="server" ControlToValidate="User_NameControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_NameMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_NameControl"></asp:RegularExpressionValidator>
</EditItemTemplate>
<InsertItemTemplate>
<ISEP:PFTextBox ID="User_NameControl" runat="server" Text='<%# Bind("User_Name") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_NameRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:CustomValidator id="CustomValidatorUserNameExisting" ControlToValidate="User_NameControl" ClientValidationFunction="UserNameExistingValidate"
Display="Static" ErrorMessage="User Name already exists. Please enter a different user name." ForeColor="red" runat="server" Enabled="false"/>
<asp:RequiredFieldValidator
ID="User_NameControlRequiredFieldValidator" runat="server" ControlToValidate="User_NameControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_NameMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_NameControl"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<ISEP:PFLabel ID="User_NameLabel" runat="server" Text='<%# Bind("User_Name") %>'
CssClass="DetViewText Label DataWindowControl" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="User_Password">
<EditItemTemplate>
<ISEP:PFTextBox ID="User_PasswordControl" TextMode="Password" runat="server" Text='<%# Bind("User_Password") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_PasswordRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:RequiredFieldValidator
ID="User_PasswordControlRequiredFieldValidator" runat="server" ControlToValidate="User_PasswordControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_PasswordMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_PasswordControl"></asp:RegularExpressionValidator>
</EditItemTemplate>
<InsertItemTemplate>
<ISEP:PFTextBox ID="User_PasswordControl" TextMode="Password" runat="server" Text='<%# Bind("User_Password") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_PasswordRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:RequiredFieldValidator
ID="User_PasswordControlRequiredFieldValidator" runat="server" ControlToValidate="User_PasswordControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_PasswordMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>80" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_PasswordControl"></asp:RegularExpressionValidator>
</InsertItemTemplate>
</asp:TemplateField>
I do not why User_Name is passed to DetailsViewUpdatedEventArgs and DetailsViewInsertedEventArgs but User_Password is not.
Except for OnItemUpdated and OnItemInserted, where can I debug these fields?
Thanks,

Related

RequiredValidator is not working in asp.net

I want to validate some text box and dropdownlist control not to empty, like below highlight part:
and my GridView control code looks like below:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EMPLOYEEID"
DataSourceID="SqlDataSource1" ShowFooter="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField>
<FooterTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">Insert</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EMPLOYEEID" SortExpression="EMPLOYEEID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("EMPLOYEEID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("EMPLOYEEID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtInsertEmpID" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsertEmpID" ControlToValidate="txtInsertEmpID"
Text="*" ForeColor="Red" ValidationGroup="Insert" runat="server" ErrorMessage="EmployeeID is required" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NAME" SortExpression="NAME">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("NAME") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEditName" ControlToValidate="TextBox1" Text="*"
ForeColor="Red" runat="server" ErrorMessage="EmployeeName is required" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("NAME") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtInsertName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsertName" ControlToValidate="txtInsertName"
Text="*" ForeColor="Red" ValidationGroup="Insert" runat="server" ErrorMessage="EmployeeName is required" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DEPTID" SortExpression="DEPTID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" SelectedValue='<%# Bind("DEPTID") %>' runat="server">
<asp:ListItem>Select Department</asp:ListItem>
<asp:ListItem Value="1">SM</asp:ListItem>
<asp:ListItem Value="2">CDS</asp:ListItem>
<asp:ListItem Value="3">AM</asp:ListItem>
<asp:ListItem Value="4">FS</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvEditDept" ControlToValidate="DropDownList1" Text="*"
ForeColor="Red" runat="server" ErrorMessage="Department is required" InitialValue="Select Department" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("DEPTID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlInsertDeptID" runat="server">
<asp:ListItem>Select Department</asp:ListItem>
<asp:ListItem Value="1">SM</asp:ListItem>
<asp:ListItem Value="2">CDS</asp:ListItem>
<asp:ListItem Value="3">AM</asp:ListItem>
<asp:ListItem Value="4">FS</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvInsertDept" ControlToValidate="ddlInsertDeptID"
Text="*" ForeColor="Red" ValidationGroup="Insert" runat="server" ErrorMessage="Department is required"
InitialValue="Select Department" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Insert"
ForeColor="Blue" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" ForeColor="Red" />
I'm not sure what's the problem so that when I click Insert link button the page was submitted without any error message even though I don't type anything in the bottom of text boxes.
can anybody help me?
You are just Missing Validation Group in Insert LinkButton.
<asp:LinkButton ID="LinkButton1" runat="server" ValidationGroup="Insert">Insert</asp:LinkButton>
Please use following code for required field by removing your
InitialValue="Select Department" and ErrorMessage="Department is required"
<asp:RequiredFieldValidator ID="rfvInsertDept" ControlToValidate="ddlInsertDeptID" Text="*" ForeColor="Red" ValidationGroup="Insert" runat="server">Department is required</asp:RequiredFieldValidator>

RequiredFieldValidator is not Valid even if there is values

I have a Page Fruit that has a UpdatePanel P1 and a ModalWIndow (outside of the updatepanel). I have a Page Apple with An UpdatePanel P2. ModalWindow on Page fruit will add Page Apple on demand.
Now, In the Apple Page
I have a GridView with EditItemTemplate and FooterItemtemplate for lets say 5 columns. Both of them have RegularExpressionValidator and RequiredFieldValidtor each separated by ValidationGroup. For EditItemTemplate everything is on point.
For FooterItemTemplate, the button won't do postback even though all the validation is met.
The footer template looks like this for the column of interest
<FooterTemplate>
<asp:TextBox ID="vendorAdd" runat="server" Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator66" ControlToValidate="vendorAdd" ValidationGroup="AddValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
<asp:RequiredFieldValidator id = "RegularExpressionValidator67" ValidationGroup="AddValidation" ControlToValidate="vendorAdd"
runat="server" ErrorMessage="VendorName Required" />
</FooterTemplate>
There is no message saying this failed. I removed the all the other validation on other footer column than shown above. I added on the button to stop validation. And in Server side added this
Page.Validate("AddValidation");
var b = Page.IsValid;
var notValidValidators = Page.Validators.Cast<IValidator>().Where(v => !v.IsValid);`
Here in the debugger the notValidValidator says that RequiredFieldValidator is not Valid. I don't see why though, I have a value and there is no message on the front end.
Update Panel on Apple Page full Code is below
<asp:UpdatePanel ID="ackPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="ackedItems" runat="server" Width="720" Visible="true" DataKeyNames="AckId" RowStyle-Height="10px"
AutoGenerateColumns="False" BorderStyle="Dotted" BorderWidth="1px" CellPadding="2"
BackColor="White" BorderColor="#CCCCCC" HorizontalAlign="Left" AllowPaging="false"
ShowFooter="true" OnRowUpdating="AckedItems_RowUpdating" OnRowDeleting="AckedItems_RowDeleting"
OnRowEditing="AckedItems_RowEditing" OnRowCommand="AckedItems_RowCommand" OnRowDataBound="AckedItems_RowDataBound">
<RowStyle ForeColor="#000066" Font-Size="8pt" />
<HeaderStyle ForeColor="#336699" Font-Size="8pt" CssClass="GridViewHeader" Height="20px" />
<AlternatingRowStyle CssClass="GridViewAltStyle" />
<Columns >
<asp:BoundField DataField="AckId" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Vendor" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="vendor" runat="server" Text='<%# Bind("VendorName") %>' Width="95%"/>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="vendorEdit" runat="server" Text='<%# Bind("VendorName") %>' Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="vendorEdit" ValidationGroup="EditValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
<asp:RequiredFieldValidator id = "Ab" ValidationGroup="EditValidation" ControlToValidate="vendorEdit"
runat="server" ErrorMessage="VendorName Required" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="vendorAdd" runat="server" Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator66" ControlToValidate="vendorAdd" ValidationGroup="AddValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
<asp:RequiredFieldValidator id = "RegularExpressionValidator67" ValidationGroup="AddValidation" ControlToValidate="vendorAdd"
runat="server" ErrorMessage="VendorName Required" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" HeaderStyle-Width="10px">
<ItemTemplate>
<asp:Label ID="amount" DataFormatString = "{0:C2}" runat="server" Text='<%# Bind("Amount") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="amountEdit" runat="server" Text='<%# Bind("Amount") %>' Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" ControlToValidate="amountEdit" ValidationGroup="EditValidation"
ValidationExpression="\d*(\.\d*)?" runat="server" ErrorMessage="Invalid Amount" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="EditValidation" ControlToValidate="amountEdit"
runat="server" ErrorMessage="Amount Required" />
</EditItemTemplate>
<FooterTemplate >
<asp:TextBox ID="amountAdd" runat="server"
Width="95%" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" ControlToValidate="amountAdd" ValidationGroup="AddValidation"
ValidationExpression="\d*(\.\d*)?" runat="server" ErrorMessage="Invalid Amount" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="type" runat="server" Text='<%# Bind("Type") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="typeEdit" runat="server" Text='<%# Bind("Type") %>' Width="95%" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" ControlToValidate="typeEdit" ValidationGroup="EditValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid Type" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" ValidationGroup="EditValidation" ControlToValidate="typeEdit"
runat="server" ErrorMessage="Type Required" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="typeAdd" runat="server" Width="95%" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" ControlToValidate="typeAdd"
ValidationGroup="AddValidation" ValidationExpression="\w*" runat="server" ErrorMessage="Invalid Type" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProgNum" ReadOnly="true" HeaderText="ProgNum" ControlStyle-Width="95%" />
<asp:TemplateField HeaderText="AckDate">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Convert.ToDateTime(Eval("AckDate")).ToString("MM/dd/yyyy") %>' Width="95%"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" >
<ItemTemplate>
<asp:Label ID="notes" runat="server" Text='<%# Bind("Notes") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="notesEdit" Text='<%# Bind("Notes") %>' runat="server" Width="95%"/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="notesAdd" runat="server" Width="95
%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ActivityDate">
<ItemTemplate>
<asp:Label ID="activityDate" runat="server" Text='<%#Convert.ToDateTime(Eval("activityDate")).ToString("MM/dd/yyyy") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="activityDateEdit" Text='<%#Convert.ToDateTime(Eval("activityDate")).ToString("MM/dd/yyyy") %>' runat="server" CssClass="date" Width="95%" />
<asp:CompareValidator ID="CompareValidator1" runat="server" Type="Date" Operator="DataTypeCheck" ValidationGroup="EditValidation"
ControlToValidate="activityDateEdit" ErrorMessage="Invalid Date" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" ValidationGroup="EditValidation" ControlToValidate="activityDateEdit"
runat="server" ErrorMessage="Date Required" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="activityDateAdd" runat="server" CssClass="date" Width="95%"/>
<asp:CompareValidator ID="CompareValidator2" runat="server" Type="Date" Operator="DataTypeCheck" ValidationGroup="AddValidation"
ControlToValidate="activityDateAdd" ErrorMessage="Invalid Date" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IsVoid">
<ItemTemplate>
<asp:CheckBox ID="isVoid" runat="server" Checked='<%# Eval("IsVoid") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="isVoidEdit" runat="server" Checked='<%# Eval("IsVoid") %>' Width="95%" />
</EditItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="isVoidAdd" runat="server" Width="95%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VoidReason">
<ItemTemplate>
<asp:Label ID="voidReason" runat="server" Text='<%# Bind("VoidReason") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="voidReasonEdit" runat="server" Width="95%" />
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="voidReasonAdd" runat="server" Width="95%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="false" CommandName="Edit"
Text="<img border=0 src=../Theme/Main/Images/edit.gif alt=Edit>" />
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Delete"
OnClientClick="if(!confirm('Do You Really want to Delete this Order Item?')) return false;"
Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Delete>" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbAdd" runat="server" CausesValidation="true" CommandName="Update"
ValidationGroup="EditValidation" Text="<img border=0 src=../Theme/Main/Images/check.gif alt=Update>" />
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Cancel"
Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Cancel>" />
</EditItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Top" />
<FooterTemplate>
<asp:LinkButton ID="lbAdd" runat="server" CausesValidation="false" CommandName="Add"
ValidationGroup="AddValidation" Text="<img border=0 src=../Theme/Main/Images/check.gif alt=Add>" />
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Cancel"
Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Cancel>" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:TextBox ID="vendorEdit" runat="server" Text='<%# Bind("Vendor") %>' CssClass="InputTextBox"
Width="100px" />
</EmptyDataTemplate>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbEdit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

Disable editing on specific rows in Gridview asp.net

I have one Gridview that Shows my Customer table. In my gridview it's possible for the user to Insert new customers and also edit existing customers.
Now to my question. I have two customers that shouldnt be able for the user to edit but i want them to be showed in the gridview. Can i somehow disable the edit button or something for this customers? For example by saying that where = custID IN (60,61) edit button disabled?
Here is the whole code for my gridview
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" DataKeyNames="CustID" DataSourceID="Event" GridLines="Horizontal" ShowFooter="True" AllowPaging="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px">
<AlternatingRowStyle BackColor="#F7F7F7" HorizontalAlign="Center" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="CustID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("CustID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("CustID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ValidationGroup="INSERT" OnClick="lbInsert_Click" ID="lbInsert" runat="server" >Insert</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Anrede" SortExpression="Gender">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource1" DataTextField="Gender" DataValueField="Gender" SelectedValue='<%# Bind("Gender") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EventConnectionString %>" SelectCommand="SELECT DISTINCT [Gender] FROM [Customer]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Gender") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label13" runat="server" Text="Anrede"></asp:Label>
<asp:DropDownList ID="ddlGender" runat="server">
<asp:ListItem>Anrede Auswählen</asp:ListItem>
<asp:ListItem>Herr</asp:ListItem>
<asp:ListItem>Frau</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvInsGender" runat="server" ErrorMessage="Anrede ist ein Pflichtfeld"
ControlToValidate="ddlGender" ValidationGroup="INSERT" Text="*" ForeColor="Red" InitialValue="Anrede Auswählen">
</asp:RequiredFieldValidator>
</div>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEdLastName" runat="server" ErrorMessage="Name ist ein Pflichtfeld"
ControlToValidate="TextBox2" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label14" runat="server" Text="Name"></asp:Label></div>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsLastName" runat="server" ErrorMessage="Name ist ein Pflichtfeld"
ControlToValidate="txtLastName" ValidationGroup="INSERT" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vorname" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEdFirstName" runat="server" ErrorMessage="VorName ist ein Pflichtfeld"
ControlToValidate="TextBox3" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label15" runat="server" Text="Vorname"></asp:Label></div>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsFirstName" runat="server" ErrorMessage="VorName ist ein Pflichtfeld"
ControlToValidate="txtFirstName" ValidationGroup="INSERT" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Strasse" SortExpression="Street">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Street") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEdStreet" runat="server" ErrorMessage="Strasse ist ein Pflichtfeld"
ControlToValidate="TextBox4" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Street") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label16" runat="server" Text="Strasse"></asp:Label></div>
<asp:TextBox ID="txtStreet" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsStreet" runat="server" ErrorMessage="Strasse ist ein Pflichtfeld"
ControlToValidate="txtStreet" ValidationGroup="INSERT" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="House Nr" SortExpression="HouseNr">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("HouseNr") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEdHouseNr" runat="server" ErrorMessage="House Nr ist ein Pflichtfeld"
ControlToValidate="TextBox5" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("HouseNr") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label17" runat="server" Text="House Nr"></asp:Label></div>
<asp:TextBox ID="txtHouseNr" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsHouseNr" runat="server" ErrorMessage="House Nr ist ein Pflichtfeld"
ControlToValidate="txtHouseNr" ValidationGroup="INSERT" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PLZ" SortExpression="Zip">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Zip") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEdZip" runat="server" ErrorMessage="PLZ ist ein Pflichtfeld"
ControlToValidate="TextBox6" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Zip") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label18" runat="server" Text="PLZ"></asp:Label></div>
<asp:TextBox ID="txtZip" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsZip" runat="server" ErrorMessage="PLZ ist ein Pflichtfeld"
ControlToValidate="txtZip" ValidationGroup="INSERT" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ort" SortExpression="City">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEdCity" runat="server" ErrorMessage="Ort ist ein Pflichtfeld"
ControlToValidate="TextBox7" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("City") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label19" runat="server" Text="Ort"></asp:Label></div>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsCity" runat="server" ErrorMessage="Ort ist ein Pflichtfeld"
ControlToValidate="txtCity" ValidationGroup="INSERT" Text="*" ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Telefon" SortExpression="Phone">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label20" runat="server" Text="Telefon"></asp:Label></div>
<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="E-mail" SortExpression="Email">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label21" runat="server" Text="E-mail"></asp:Label></div>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Firma" SortExpression="Company">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("Company") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("Company") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label22" runat="server" Text="Firma"></asp:Label></div>
<asp:TextBox ID="txtCompany" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" SortExpression="Active">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource2" DataTextField="Active" DataValueField="Active" SelectedValue='<%# Bind("Active") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:EventConnectionString %>" SelectCommand="SELECT DISTINCT [Active] FROM [Customer]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("Active") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="text-align: center;"><asp:Label ID="Label23" runat="server" Text="Status"></asp:Label></div>
<asp:DropDownList ID="ddlActive" runat="server">
<asp:ListItem>Status Auswählen</asp:ListItem>
<asp:ListItem>Aktiv</asp:ListItem>
<asp:ListItem>Passiv</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvInsActive" runat="server" ErrorMessage="Status ist ein Pflichtfeld"
ControlToValidate="ddlActive" ValidationGroup="INSERT" Text="*" ForeColor="Red" InitialValue="Status Auswählen">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#B5C7DE" Font-Bold="True" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
I would suggest to loop through the records using RowDataBound method and then on the CustID field look for 60 and 61 and then disable the entire Row:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var dr = e.Row.DataItem as DataRowView;
if(dr["CustID"].ToString() == "60" || dr["CustID"].ToString() == "61")
{
e.Row.Enabled = false; //OR dr.Enabled = false;
//DISABLED Controls only
//((TextBox)e.Row.FindControl("TextBox1")).Enabled = false;
}
}
}
Remember to add OnRowDataBound="GridView1_RowDataBound" in the GridView markup declaration

how to check if textbox is not empty in formview

i have a page where i can create users that can then log into the page. on the page where i create the users, there is a formview. in this formview there are multiple textboxes and dropdownlists. how can i check if the textboxes are empty? i tried to do it code-behind but i cant access the textboxes from there...
here is my code:
<asp:FormView ID="fvBenutzer" runat="server" DefaultMode="Insert" DataKeyNames="BenutzerID" DataSourceID="SqlDataSource1">
<InsertItemTemplate>
Gruppe:
<asp:TextBox ID="tbGruppe" runat="server" Text='<%# Bind("GruppenID") %>' /><br />
Titel:
<asp:TextBox ID="tbTitel" runat="server" Text='<%# Bind("Titel") %>' /><br />
Bezeichnung:
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnBezeichnung" Text='<%# Bind("Bezeichnung")%>'>
<asp:ListItem Text="Mitarbeiter" Value="Mitarbeiter"></asp:ListItem>
<asp:ListItem Text="Praktikant" Value="Praktikant"></asp:ListItem>
<asp:ListItem Text="Azubi" Value="Azubi"></asp:ListItem>
<asp:ListItem Text="Umschüler" Value="Umschüler"></asp:ListItem>
</asp:DropDownList><br />
Vorname:
<asp:TextBox runat="server" ID="tbVorname" Text='<%# Bind("Vorname")%>' /><br />
Nachname:
<asp:TextBox runat="server" ID="tbNachname" Text='<%# Bind("Nachname")%>' /><br />
Geburtsdatum:
<asp:TextBox runat="server" ID="tbGeburtsdatum" Text='<%# Bind("Geburtsdatum")%>' /><br />
Geburtsort:
<asp:TextBox runat="server" ID="tbGeburtsort" Text='<%# Bind("Geburtsort")%>' /><br />
Nationalität:
<asp:TextBox runat="server" ID="tbNationalitaet" Text='<%# Bind("Nationalität")%>' /><br />
Straße:
<asp:TextBox runat="server" ID="tbStraße" Text='<%# Bind("Straße")%>' /><br />
Hausnummer:
<asp:TextBox runat="server" ID="tbHausnummer" Text='<%# Bind("Hausnummer")%>' /><br />
PLZ:
<asp:TextBox runat="server" ID="tbPLZ" Text='<%# Bind("PLZ")%>' /><br />
Ort:
<asp:TextBox runat="server" ID="tbOrt" Text='<%# Bind("Ort")%>' /><br />
Land:
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnLand" Text='<%# Bind("Land")%>'>
</asp:DropDownList><br />
Mobil:
<asp:TextBox runat="server" ID="tbMobil" Text='<%# Bind("Mobil")%>' /><br />
Fax:
<asp:TextBox runat="server" ID="tbFax" Text='<%# Bind("Fax")%>' /><br />
Festnetz:
<asp:TextBox runat="server" ID="tbFestnetz" Text='<%# Bind("Festnetz")%>' /><br />
Email:
<asp:TextBox runat="server" ID="tbEmail" Text='<%# Bind("Email")%>' /><br />
Homepage:
<asp:TextBox runat="server" ID="tbBenutzerart" Text='<%# Bind("Homepage")%>' /><br />
Benutzerart:
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnBenutzerart" Text='<%# Bind("Benutzerart")%>'>
<asp:ListItem Text="Mitarbeiter" Value="Mitarbeiter"></asp:ListItem>
<asp:ListItem Text="Geschäftsführung" Value="Geschäftsführung"></asp:ListItem>
<asp:ListItem Text="Führungskraft" Value="Führungskraft"></asp:ListItem>
<asp:ListItem Text="Administrator" Value="Administrator"></asp:ListItem>
</asp:DropDownList><br />
Urlaubstage:
<asp:TextBox runat="server" ID="tbUrlaubstageInsgesamt" Text='<%# Bind("UrlaubstageInsgesamt")%>' /><br />
Benutzername:
<asp:TextBox runat="server" ID="tbBenutzername" Text='<%# Bind("Username")%>' /><br />
Passwort:
<asp:TextBox runat="server" ID="tbPasswort" Text='<%# Bind("UserPassword")%>' /><br />
<br />
<asp:Button ID="btnSpeichern" runat="server" CommandName="Insert" Text="Speichern" />
<asp:Button ID="btnAbbrechen" Text="Abbrechen" runat="server" OnClick="btnAbbrechen_Click" />
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource OnInserting="SqlDataSource1_Inserting" OnInserted="SqlDataSource1_Inserted" ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="INSERT INTO Benutzer (GruppenID, Titel, Bezeichnung, Vorname, Nachname, Geburtsdatum, Geburtsort, Nationalität, Straße, Hausnummer, PLZ, Ort, Land, Mobil, Fax, Festnetz,
Email, Homepage, Benutzerart, UrlaubstageInsgesamt , UrlaubstageRest, Username, UserPassword)
VALUES (#GruppenID, #Titel, #Bezeichnung, #Vorname, #Nachname, #Geburtsdatum, #Geburtsort, #Nationalität, #Straße, #Hausnummer, #PLZ, #Ort, #Land, #Mobil, #Fax, #Festnetz,
#Email, #Homepage, #Benutzerart, #UrlaubstageInsgesamt , #UrlaubstageInsgesamt, #Username, #UserPassword)"></asp:SqlDataSource>
protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
//Code to check textboxes goes here...
}
Have you tried:
TextBox tb = (TextBox)fvBenutzer.FindControl("yourtextboxid");
string text = tb.Text;
Edit:
You can stop the insert in the FormView ItemInserting event. For example:
protected void fvBenutzer_ItemInserting(object sender, FormViewInsertEventArgs e)
{
if(YourValidationCheck() == false)
e.Cancel = true;
}
Don't forget to add oniteminserting="fvBenutzer_ItemInserting" to the FormView tag.

data grid with edit option error when click on edit

I am getting the following "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." error. How can I avoid this error?
This is my code for editing the data from grid view:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Width="950px">
<asp:Label ID="lblMessage" runat="Server" ForeColor="Red"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="2"
DataKeyNames="DOC_id" ForeColor="Black" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
onrowcommand="GridView1_AddRow" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" Height="392px" ShowFooter="True">
<FooterStyle BackColor="Tan" />
<AlternatingRowStyle BackColor="pink" />
<Columns>
<asp:templatefield showheader="False">
<edititemtemplate>
<asp:linkbutton causesvalidation="True" commandname="Update"
id="LinkButton1" runat="server" text="Update"></asp:linkbutton>
<asp:linkbutton causesvalidation="False" commandname="Cancel"
id="LinkButton2" runat="server" text="Cancel"></asp:linkbutton>
</edititemtemplate>
<footertemplate>
<asp:linkbutton commandname="AddNew" id="AddNew" runat="server">Add
New</asp:linkbutton>
</footertemplate>
<itemtemplate>
<asp:linkbutton causesvalidation="False" commandname="Edit" id="LinkButton1"
runat="server" text="Edit"></asp:linkbutton>
</itemtemplate>
</asp:templatefield>
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the
record?')">
<asp:LinkButton ID="lnkB" runat="Server" Text="Delete"
CommandName="Delete"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DOC_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DOC_id") %>'>
</asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox22" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator22" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox22">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DOC_id") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Type">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Dr_Type") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="TextBox1">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox1">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Dr_Type") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Title">
<EditItemTemplate>
<asp:DropDownList ID="TextBox2" runat="server" selectedvalue='<%#
Bind("Dr_Title") %>'>
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Mr.</asp:ListItem>
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
<asp:ListItem>Fr.</asp:ListItem>
<asp:ListItem>Sr.</asp:ListItem>
<asp:ListItem>Rev.</asp:ListItem>
<asp:ListItem>Dr.</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="TextBox2">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="NewTextBox2" runat="server" >
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Mr.</asp:ListItem>
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
<asp:ListItem>Fr.</asp:ListItem>
<asp:ListItem>Sr.</asp:ListItem>
<asp:ListItem>Rev.</asp:ListItem>
<asp:ListItem>Dr.</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox2">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Dr_Title") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Dr_FirstName")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage="*" ControlToValidate="TextBox3">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator3" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox3">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Dr_FirstName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_MiddleName">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Dr_MiddleName")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage="*" ControlToValidate="TextBox4">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox4" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator4" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox4">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Dr_MiddleName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Dr_LastName") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ErrorMessage="*" ControlToValidate="TextBox5">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox5" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator5" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox5">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Dr_LastName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Suffix">
<EditItemTemplate>
<asp:DropDownList ID="TextBox6" runat="server" selectedvalue='<%#
Bind("Dr_Suffix") %>'>
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Sr</asp:ListItem>
<asp:ListItem>Jr</asp:ListItem>
<asp:ListItem>III</asp:ListItem>
<asp:ListItem>IV</asp:ListItem>
<asp:ListItem>DMD</asp:ListItem>
<asp:ListItem>DO</asp:ListItem>
<asp:ListItem>DDS</asp:ListItem>
<asp:ListItem>MD</asp:ListItem>
<asp:ListItem>PHD</asp:ListItem>
<asp:ListItem>DVM</asp:ListItem>
<asp:ListItem>Esq</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ErrorMessage="*" ControlToValidate="TextBox6">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="NewTextBox6" runat="server">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Sr</asp:ListItem>
<asp:ListItem>Jr</asp:ListItem>
<asp:ListItem>III</asp:ListItem>
<asp:ListItem>IV</asp:ListItem>
<asp:ListItem>DMD</asp:ListItem>
<asp:ListItem>DO</asp:ListItem>
<asp:ListItem>DDS</asp:ListItem>
<asp:ListItem>MD</asp:ListItem>
<asp:ListItem>PHD</asp:ListItem>
<asp:ListItem>DVM</asp:ListItem>
<asp:ListItem>Esq</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator6" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox6">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Dr_Suffix") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Degree">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Dr_Degree") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ErrorMessage="*" ControlToValidate="TextBox7">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox7" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator7" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox7">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Dr_Degree") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_PreferredUsername">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%#
Bind("Dr_PreferredUsername") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ErrorMessage="*" ControlToValidate="TextBox8">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox8" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator8" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox8">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Dr_PreferredUsername")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_ContactNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Dr_ContactNumber")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ErrorMessage="*" ControlToValidate="TextBox9">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3"
runat="server"
ControlToValidate="TextBox9"
ErrorMessage="Invalid Contact Number....!!" ForeColor="Red"
ValidationExpression="^[9,8,7][0-9]{9}$"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox9" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator9" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox9">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4"
runat="server"
ControlToValidate="NewTextBox9"
ErrorMessage="Invalid Contact Number....!!" ForeColor="Red"
ValidationExpression="^[9,8,7][0-9]{9}$"></asp:RegularExpressionValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("Dr_ContactNumber")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_FaxNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("Dr_FaxNumber")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
ErrorMessage="*" ControlToValidate="TextBox10">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox10" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator10" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox10">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("Dr_FaxNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_EmailAddress">
<EditItemTemplate>
<asp:TextBox ID="TextBox11" runat="server" Text='<%# Bind("Dr_EmailAddress")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
ErrorMessage="*" ControlToValidate="TextBox11">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5"
runat="server"
ControlToValidate="TextBox11" ErrorMessage="Invalid Email ID....!!"
ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox11" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator11" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox11">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6"
runat="server"
ControlToValidate="NewTextBox11" ErrorMessage="Invalid Email ID....!!"
ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("Dr_EmailAddress")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_SpecialtyArea">
<EditItemTemplate>
<asp:DropDownList ID="TextBox12" runat="server" selectedvalue='<%#
Bind("Dr_SpecialtyArea") %>'
DataSourceID="SqlDataSource3" DataTextField="Speciality"
DataValueField="Speciality">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:DBCS %>"
SelectCommand="SELECT [Speciality] FROM [Doc_Speciality]">
</asp:SqlDataSource>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server"
ErrorMessage="*" ControlToValidate="TextBox12">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="NewTextBox12" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Speciality"
DataValueField="Speciality">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:DBCS %>"
SelectCommand="SELECT [Speciality] FROM [Doc_Speciality]">
</asp:SqlDataSource>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator12" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox12">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("Dr_SpecialtyArea")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
</asp:Panel>
<asp:LinkButton ID="AddNew" runat="server" Text="AddNew"
onclientclick="imgbtn_Click" onclick="AddNew_Click"></asp:LinkButton>
</asp:Content>`
Try this solution:
http://w3ka.blogspot.com/2007/09/dropdownlist-in-gridview.html
You have to create a DataBound event for the DropDownLists that use the SqlDataSource and set the SelectedValue there.

Resources