ISSUE :
 
Profile photo
Submitted by Amvigill
on August 13th, 2012 at 16:04:13 EST

Autopostback resets DropDownList in DetailsView

Hi,

I have two drop down lists inside of two different fields in a detailsview, the first one determines the values of the second one.

When i select a value from the first ddl autopostback erases all data already in the detailsview and reverts the first dropdownlist back to the first selection.

Also when i select from the list (change the ddl selection more than once) it will throw a :

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

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.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Source Error:

[No relevant source lines]


-------First DDL

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SQLLEAVECODE"
DataTextField="LEAVETYPE" DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="80px">
<asp:ListItem> </asp:ListItem>
</asp:DropDownList>

-------Second DDL

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
DataTextField="REASON" DataValueField="REASON"
SelectedValue='<%# Bind("leavetype") %>'>
</asp:DropDownList>



---------page load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsView1.DataBind();
}
}


--------DDL 1 selectedIndexChange
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
Label27.Text = lvtype.SelectedValue.ToString();

DetailsView1.Fields[4].Visible = true;
}


Profile photo
Replied by SBajra
on August 14th, 2012 at 10:37:22 EST
You mentioned that "two drop down lists inside of two different fields in a detailsview".
Can you please include your .aspx control code for your detailsview?

Profile photo
Replied by Amvigill
on August 14th, 2012 at 12:39:36 EST
 <asp:DetailsView ID="DetailsView1" runat="server" 
DataSourceID="ObjectDataSource1" DataKeyNames="bwrequestid"
Height="29px" Width="928px" AutoGenerateRows="False" CellPadding="4" ForeColor="#333333"
GridLines="None" Style="margin-right: 0px; text-align: left; margin-top: 0px;"
ondatabound="DetailsView1_DataBound"
oniteminserted="DetailsView1_ItemInserted" oninit="DetailsView1_Init"
onitemcommand="DetailsView1_ItemCommand" >
<Fields>
<asp:TemplateField HeaderText="Leave Type" SortExpression="reqleavecode">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="SQLLEAVECODE"
DataTextField="LEAVETYPE" style="text-transform:uppercase;" DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="166px" Height="19px"><asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:DropDownExtender ID="DropDownList6_DropDownExtender" runat="server"
DynamicServicePath="" Enabled="True" TargetControlID="DropDownList6">
</asp:DropDownExtender>
<asp:SqlDataSource ID="SQLLEAVECODE" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT LEAVETYPE, LEAVECODE FROM BWLVTYPE ORDER BY LEAVECODE">
</asp:SqlDataSource>
<asp:Label ID="Label26" runat="server" Text='<%# bind("reqleavecode") %>'></asp:Label>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("reqleavecode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Leave Type" HeaderText="Leave Reason"
Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("leavetype") %>' Height="21px"
Width="43px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="SqlDataSource1"
DataTextField="REASON" DataValueField="REASON"
SelectedValue='<%# Bind("leavetype") %>'
onselectedindexchanged="DropDownList5_SelectedIndexChanged1">
</asp:DropDownList>
<asp:DropDownExtender ID="DropDownList5_DropDownExtender" runat="server"
DynamicServicePath="" Enabled="True" TargetControlID="DropDownList5">
</asp:DropDownExtender>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT REASON, LEAVECODE FROM BWLEAVRSN">
<SelectParameters>
<asp:ControlParameter ControlID="Label27" Name="LEAVECODE" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("leavetype") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
Edited on August 14th, 2012 at 12:58:31 EST

Profile photo
Replied by SBajra
on August 14th, 2012 at 16:00:20 EST
Amvigill,
Looking at the code your provided, seems like it should work. Do you have any logic in page_load() to reset the data or anything to do with databinding?

Profile photo
Replied by Amvigill
on August 14th, 2012 at 18:13:02 EST
Here is the relevant part of my code behind.


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsView1.DataBind();
}

}


protected void DropDownList6_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));

Label27.Text = lvtype.SelectedValue.ToString().ToUpper();
Label l26 = (Label)(DetailsView1.FindControl("label26"));
l26.Text = lvtype.SelectedValue.ToString().ToUpper();


if (Label27.Text.ToString() == "4 " || Label27.Text.ToString() == "1F")
{
DetailsView1.Fields[4].Visible = true;
}
else
{
DetailsView1.Fields[4].Visible = false;
}

}
Edited on August 14th, 2012 at 18:13:34 EST

Profile photo
Replied by SBajra
on August 15th, 2012 at 11:09:28 EST
Everything looks fine. The error you are getting is because you have databound field which you are trying to access but there is no data coming.

Try removing if condition from your page_load() and see it that helps.

Profile photo
Replied by Amvigill
on August 15th, 2012 at 11:36:33 EST
I removed the if statement, that took away the "Databinding methods such as Eval(), XPath(), and Bind()" error but it immediately changes the ddl to the first value and wont allow the second ddl to fill with any values.

Profile photo
Replied by SBajra
on August 15th, 2012 at 12:37:09 EST
Without looking your code in detail, its hard to point out the issue. If possible, can you please post your entire .aspx code and codebehind .cs code.

Please strip out any sensitive data or your business specific logic.

Profile photo
Replied by Amvigill
on August 15th, 2012 at 12:44:45 EST
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;

namespace TimeAndAttendanceUI.Authorized.LeaveRequest
{
public partial class newRequestForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsView1.DataBind();
}
}

protected void DetailsView1_DataBound(object sender, EventArgs e)
{
TextBox employeeID = (TextBox)(DetailsView1.FindControl("TextBox17"));
DropDownList approverID = (DropDownList)(DetailsView1.FindControl("DropDownList4"));

if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
var CurrUser = "";

Account.Login uusr = new Account.Login();
CurrUser = uusr.User.Identity.Name.ToString().ToUpper();

employeeID.Text = CurrUser.Substring(3, 3);

string supusrid = "";

DataHandler.DataHandler Dt = new DataHandler.DataHandler();
supusrid = Dt.SelectRequestApproverForm(supusrid);

approverID.SelectedValue = supusrid;
}
}

protected void DropDownList6_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));

Label27.Text = lvtype.SelectedValue.ToString().ToUpper();
Label l26 = (Label)(DetailsView1.FindControl("label26"));
l26.Text = lvtype.SelectedValue.ToString().ToUpper();

if (Label27.Text.ToString() == "4 " || Label27.Text.ToString() == "1F")
{
lvreason.Visible = true;
}
else
{
lvreason.Visible = false;
}

}

protected void Button2_Click(object sender, EventArgs e)
{
DetailsView1.DataSource = null;
DetailsView1.DataBind();
}

protected void Button2_Click1(object sender, EventArgs e)
{
Button3.Visible = true;
}

protected void Button3_Click(object sender, EventArgs e)
{
DetailsView1.Visible = true;
DetailsView1.ChangeMode(DetailsViewMode.Insert);
if (DetailsView1.CurrentMode.Equals(DetailsViewMode.Insert))
{
Button3.Visible = false;
Button4.Visible = false;
DetailsView2.Visible = true;
DetailsView3.Visible = true;
}
}

protected void Button4_Click(object sender, EventArgs e)
{
DetailsView4.Visible = true;
DetailsView4.ChangeMode(DetailsViewMode.Insert);
if (DetailsView1.CurrentMode.Equals(DetailsViewMode.Insert))
{
Button3.Visible = false;
Button4.Visible = false;
DetailsView2.Visible = true;
DetailsView3.Visible = true;
}
}

}

Profile photo
Replied by Amvigill
on August 15th, 2012 at 12:46:43 EST
I will post this in multiple posts because of the size

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" Debug="true"
CodeBehind="newRequestForm.aspx.cs" Inherits="" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<script runat="server">
void goToPage(object sender, System.EventArgs e){ Response.Redirect("Time.aspx");}
void goToPageHome(object sender, System.EventArgs e){ Response.Redirect("Time.aspx");}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<link type="text/css" rel="Stylesheet" href="../../Styles/Site.css" />
<style type="text/css">
.style1{width: 100%;height: 43px; margin-bottom: 0px;}
.style2{text-align: center;}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Label ID="HoursLabel" runat="server"></asp:Label>
<br />
<table class="style1">
<tr>
<td class="style2">
<asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False"
BackColor="#999999" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="ObjectDataSource2" ForeColor="Black"
GridLines="Horizontal" Height="19px" style="text-align: left; margin-bottom: 0px;" Width="509px" Visible="False">
<EditRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<FieldHeaderStyle Width="40px" />
<Fields>
<asp:TemplateField HeaderText="Name:">
<ItemTemplate>
<asp:Label ID="Label22" runat="server" Text='<%# bind("firstname") %>'></asp:Label>
&nbsp;<asp:Label ID="Label23" runat="server" Text='<%# bind("lastname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
</asp:DetailsView>
</td>
<td class="style5">
<asp:DetailsView ID="DetailsView3" runat="server" AutoGenerateRows="False"
BackColor="#999999" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="ObjectDataSource2" ForeColor="Black"
GridLines="Horizontal" Height="24px"
style="text-align: left; margin-bottom: 0px; " Width="418px" Visible="False">
<EditRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<FieldHeaderStyle Width="100px" />
<Fields>
<asp:TemplateField HeaderText="Employee ID:">
<ItemTemplate>
<asp:Label ID="Label25" runat="server" Text='<%# bind("bwempid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
</asp:DetailsView>
</td>

</tr>
Edited on August 15th, 2012 at 12:47:23 EST

Profile photo
Replied by Amvigill
on August 15th, 2012 at 12:49:36 EST
<tr>
<td class="style2" colspan="2">
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="ObjectDataSource1" DataKeyNames="bwrequestid"
Height="29px" Width="928px" AutoGenerateRows="False" CellPadding="4" ForeColor="#333333"
GridLines="None" Style="margin-right: 0px; text-align: left; margin-top: 0px;"
ondatabound="DetailsView1_DataBound"
oniteminserted="DetailsView1_ItemInserted"
onitemcommand="DetailsView1_ItemCommand" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" Width="180px" />
<Fields>
<asp:TemplateField AccessibleHeaderText="Request ID" HeaderText="Leave Request ID" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label18" runat="server" Text='<%# Bind("bwrequestid") %>'></asp:Label>
<asp:TextBox ID="TextBox169" runat="server" Text='<%# bind("bwrequestid") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="Label19" runat="server" Text='<%# Bind("bwrequestid") %>'></asp:Label>
<asp:TextBox ID="TextBox165" runat="server" Text='<%# bind("bwrequestid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("bwrequestid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Employee ID" HeaderText="Employee ID" >
<EditItemTemplate>
<asp:Label ID="Label20" runat="server" Text='<%# bind("emppid") %>'></asp:Label>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="Label21" runat="server" Text='<%# bind("emppid") %>'></asp:Label>
<asp:TextBox ID="TextBox17" runat="server" Text='<%# bind("emppid") %>'
></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# bind("emppid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Approver ID" HeaderText="Approver ID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("approverid") %>' Height="21px"
Width="68px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" style="text-transform:uppercase;" DataSourceID="SqlDataSourceApprover"
DataTextField="APPROVNAME" DataValueField="APPROVERID"
SelectedValue='<%# Bind("approverid") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceApprover" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT APPROVERID, APPROVNAME FROM APPROVER ORDER BY APPROVERID">
</asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("approverid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Edited on August 15th, 2012 at 12:50:05 EST

Profile photo
Replied by Amvigill
on August 15th, 2012 at 12:50:43 EST
The first dropdownlist

                    <asp:TemplateField HeaderText="Leave Type" SortExpression="reqleavecode">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList7" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SQLLEAVECODE"
style="text-transform:uppercase;" DataTextField="LEAVETYPE"
DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
SelectedValue='<%# BIND("REQLEAVECODE") %>' ViewStateMode="Enabled"
Width="165px" Height="19px">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="SQLLEAVECODE"
DataTextField="LEAVETYPE" style="text-transform:uppercase;" DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="166px" Height="19px"><asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SQLLEAVECODE" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT LEAVETYPE, LEAVECODE FROM BWLVTYPE ORDER BY LEAVECODE">
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="REASON"
DataValueField="REASON" Height="19px"
onselectedindexchanged="DropDownList5_SelectedIndexChanged1"
SelectedValue='<%# Bind("leavetype") %>' Visible="False" Width="163px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT REASON, LEAVECODE FROM BWLEAVRSN">
<SelectParameters>
<asp:ControlParameter ControlID="Label27" Name="LEAVECODE" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1Reason" runat="server"
ControlToValidate="DropDownList5" ErrorMessage="*Leave Reason Required"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label26" runat="server" Text='<%# bind("reqleavecode") %>'></asp:Label>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("reqleavecode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Edited on August 15th, 2012 at 12:52:09 EST

Profile photo
Replied by Amvigill
on August 15th, 2012 at 12:52:52 EST
Second DDL


<asp:TemplateField AccessibleHeaderText="Leave Type" HeaderText="Leave Reason"
Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("leavetype") %>' Height="21px"
Width="43px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("leavetype") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Reason" HeaderText="Reason"
Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("requesreason") %>' Rows="2" TextMode="MultiLine"
Width="494px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("requesreason") %>' Rows="3" TextMode="MultiLine"
Width="200px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("requesreason") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Profile photo
Replied by Amvigill
on August 15th, 2012 at 13:07:50 EST
     <asp:TemplateField AccessibleHeaderText="start date" HeaderText="Leave Date">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"
Text='<%# Bind("lstdate", "{0:MM/dd/yyyy}") %>' Height="21px"
Width="72px"></asp:TextBox>
<asp:CalendarExtender ID="TextBox5_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox5">
</asp:CalendarExtender>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"
Text='<%# Bind("lstdate", "{0:MM/dd/yyyy}") %>' Height="21px"
Width="67px"></asp:TextBox>
<asp:CalendarExtender ID="TextBox5_CalendarExtender" runat="server" Enabled="True"
TargetControlID="TextBox5">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox5" ErrorMessage="*Leave Date Required"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator18" runat="server"
ControlToCompare="TextBox7" ControlToValidate="TextBox5"
ErrorMessage="Leave date cannot be after start date" ForeColor="Red"
Operator="LessThanEqual" ToolTip="Must choose start date before end date"></asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("lstdate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="lenddate" HeaderText="Return Date">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server"
Text='<%# Bind("lenddate", "{0:MM/dd/yyyy}") %>' Height="21px" Width="67px"></asp:TextBox>
<asp:CalendarExtender ID="TextBox7_CalendarExtender" runat="server" Enabled="True"
TargetControlID="TextBox7">
</asp:CalendarExtender>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox7" runat="server"
Text='<%# Bind("lenddate", "{0:MM/dd/yyyy}") %>' Height="21px"
Width="67px"></asp:TextBox>
<asp:CalendarExtender ID="TextBox7_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox7">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox7" ErrorMessage="*Return Date Required"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox5" ControlToValidate="TextBox7"
ErrorMessage="Return date cannot be before start date" ForeColor="Red"
Operator="GreaterThanEqual"></asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("lenddate") %>'></asp:Label>
</ItemTemplate>. </asp:TemplateField>. <asp:TemplateField AccessibleHeaderText="Leave Time" HeaderText="Leave Time">
<EditItemTemplate>. <asp:TextBox ID="TextBox15" runat="server" Height="21px"
Text='<%# Bind("lsttime") %>' ToolTip="Type 'A' or 'P' to switch AM/PM"
Width="85px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox15" runat="server" Text='<%# Bind("lsttime") %>' Width="85px"
Height="22px" ToolTip="Type 'A' or 'P' to switch AM/PM"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label15" runat="server" Text='<%# Bind("lsttime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Profile photo
Replied by Amvigill
on August 15th, 2012 at 13:08:26 EST

<asp:TemplateField AccessibleHeaderText="Return Time" HeaderText="Return Time">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("lendtime") %>' Width="85px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("lsttime") %>' Width="85px"
Height="22px" ToolTip="Type 'A' or 'P' to switch AM/PM"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("lendtime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Standby" HeaderText="On Standby">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("standby") %>' MaxLength="1" Width="21px"></asp:TextBox>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource10"
DataTextField="&quot;Y/N&quot;" DataValueField="&quot;Y/N&quot;" SelectedValue='<%# BIND("standby") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource10" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>" SelectCommand="SELECT * FROM YNSELECT ORDER BY ALPH">
</asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("standby") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Reason Decline"
HeaderText="Request Decline Reason" InsertVisible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox12" style="text-transform:uppercase;" runat="server" Text='<%# Bind("rsndecline") %>'
Visible="False"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox12" runat="server" Text='<%# Bind("rsndecline") %>'
Visible="False"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("rsndecline") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Status" HeaderText="Request Status" InsertVisible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox13" runat="server" Text='<%# Bind("status") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox13" runat="server" Text='<%# Bind("status") %>' Visible="False"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Profile photo
Replied by Amvigill
on August 15th, 2012 at 13:08:48 EST

<asp:TemplateField AccessibleHeaderText="empremarks" HeaderText="Leave Request Remarks">
<EditItemTemplate>
<asp:TextBox ID="TextBox14" runat="server" style="text-transform:uppercase;" Text='<%# Bind("empremarks") %>'
TextMode="MultiLine" Height="50px" Width="449px"
ToolTip="Additional information pertaining to leave request"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox14" Display="Dynamic" Enabled="False"
ErrorMessage="*Leave Remarks Required for &quot;Other&quot; selection"
ForeColor="Red"></asp:RequiredFieldValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox14" runat="server" style="text-transform:uppercase;" Text='<%# Bind("empremarks") %>'
TextMode="MultiLine" Height="47px" Width="452px"
ToolTip="Additional information pertaining to leave request."></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%# Bind("empremarks") %>'
ToolTip="Additional information pertaining to leave request"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> &nbsp;
<asp:Button ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Insert" Text="Submit Request" /> &nbsp;
<asp:Button ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" Height="21px" onclick="Button2_Click1" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" Width="65px" Height="21px" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" /> &nbsp; &nbsp;
<asp:Button ID="Button2" runat="server" Height="21px" CausesValidation="False" CommandName="New" Width="65px" Text="New" /> &nbsp; &nbsp;
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:DetailsView>
</td>
</tr>

Profile photo
Replied by Amvigill
on August 15th, 2012 at 13:12:42 EST
      <tr>
<td class="style2" colspan="2">
<asp:Button ID="Button3" runat="server" Height="21px" onclick="Button3_Click"
Text="With Pay Leave Request" />
&nbsp;&nbsp;
<asp:Button ID="Button4" runat="server" Height="21px" onclick="Button4_Click"
Text="Without Pay Leave Request" style="margin-left: 13px" Width="221px" />
</td>
</tr>
</table>
<br />
<asp:Label ID="Label17" runat="server" ForeColor="#999999"
Text="Exhibit B PP-8"></asp:Label>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteRequestForm"
InsertMethod="InsertRequestForm" SelectMethod="SelectRequestEMPID" TypeName="TimeAndAttendanceUI.DataHandler.DataHandler"
UpdateMethod="UpdateRequestFormLastName" OldValuesParameterFormatString="original_{0}">
<DeleteParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="reqleavecode" Type="Int32" />
</InsertParameters>
<SelectParameters>
<%-- <asp:Parameter Name="emppid" Type="Decimal" />--%>
<asp:QueryStringParameter Name="emppid" QueryStringField="emppid" Type="Decimal" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="requesreason" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="LASTNAME" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="SelectNameEmployeeForm"
TypeName="TimeAndAttendanceUI.DataHandler.DataHandler">
<SelectParameters>
<asp:Parameter Name="bwempid" Type="Decimal" />
<asp:Parameter Name="firstname" Type="String" />
<asp:Parameter Name="lastname" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label ID="Label27" runat="server" ></asp:Label>
</asp:Content>

Profile photo
Replied by Amvigill
on August 15th, 2012 at 13:27:43 EST
      <tr>
<td class="style2" colspan="2">
<asp:Button ID="Button3" runat="server" Height="21px" onclick="Button3_Click"
Text="With Pay Leave Request" />
&nbsp;&nbsp;
<asp:Button ID="Button4" runat="server" Height="21px" onclick="Button4_Click"
Text="Without Pay Leave Request" style="margin-left: 13px" Width="221px" />
</td>
</tr>
</table>
<br />
<asp:Label ID="Label17" runat="server" ForeColor="#999999"
Text="Exhibit B PP-8"></asp:Label>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteRequestForm"
InsertMethod="InsertRequestForm" SelectMethod="SelectRequestEMPID" TypeName="TimeAndAttendanceUI.DataHandler.DataHandler"
UpdateMethod="UpdateRequestFormLastName" OldValuesParameterFormatString="original_{0}">
<DeleteParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="reqleavecode" Type="Int32" />
</InsertParameters>
<SelectParameters>
<%-- <asp:Parameter Name="emppid" Type="Decimal" />--%>
<asp:QueryStringParameter Name="emppid" QueryStringField="emppid" Type="Decimal" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="requesreason" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="LASTNAME" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="SelectNameEmployeeForm"
TypeName="TimeAndAttendanceUI.DataHandler.DataHandler">
<SelectParameters>
<asp:Parameter Name="bwempid" Type="Decimal" />
<asp:Parameter Name="firstname" Type="String" />
<asp:Parameter Name="lastname" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label ID="Label27" runat="server" ></asp:Label>
</asp:Content>

Profile photo
Replied by SBajra
on August 15th, 2012 at 13:34:00 EST
By the way, what version of .NET framework are you using?

And are you using ViewState? I mean do you have ViewState turned on or off?
Edited on August 15th, 2012 at 13:49:18 EST

Profile photo
Replied by Amvigill
on August 15th, 2012 at 13:53:37 EST
      <tr>
<td class="style2" colspan="2">
<asp:Button ID="Button3" runat="server" Height="21px" onclick="Button3_Click"
Text="With Pay Leave Request" />
&nbsp;&nbsp;
<asp:Button ID="Button4" runat="server" Height="21px" onclick="Button4_Click"
Text="Without Pay Leave Request" style="margin-left: 13px" Width="221px" />
</td>
</tr>
</table>
<br />
<asp:Label ID="Label17" runat="server" ForeColor="#999999"
Text="Exhibit B PP-8"></asp:Label>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteRequestForm"
InsertMethod="InsertRequestForm" SelectMethod="SelectRequestEMPID" TypeName="TimeAndAttendanceUI.DataHandler.DataHandler"
UpdateMethod="UpdateRequestFormLastName" OldValuesParameterFormatString="original_{0}">
<DeleteParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="reqleavecode" Type="Int32" />
</InsertParameters>
<SelectParameters>
<%-- <asp:Parameter Name="emppid" Type="Decimal" />--%>
<asp:QueryStringParameter Name="emppid" QueryStringField="emppid" Type="Decimal" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="bwrequestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="requesreason" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="LASTNAME" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="SelectNameEmployeeForm"
TypeName="TimeAndAttendanceUI.DataHandler.DataHandler">
<SelectParameters>
<asp:Parameter Name="bwempid" Type="Decimal" />
<asp:Parameter Name="firstname" Type="String" />
<asp:Parameter Name="lastname" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label ID="Label27" runat="server" ></asp:Label>
</asp:Content>

Profile photo
Replied by SBajra
on August 15th, 2012 at 14:44:49 EST
its hard to tell whats missing in your code. However, I wrote a similar code which works. May be this will help. Take a look.
3 files:
1) TestPage.aspx
2) TestPage.aspx.cs (CodeBehind)
3) MyName.cs (under App_Code folder for custom data)

I will be pasting source code in separate subsequent posts because of size limitation.
Accepted Answer
Accepted
 Answer

Profile photo
Replied by SBajra
on August 15th, 2012 at 14:45:17 EST
TestPage.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateInsertButton="True" AutoGenerateRows="False"
DataSourceID="ObjectDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:TemplateField HeaderText="CountryName">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="ObjectDataSource2"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
SelectedValue='<%# Bind("CountryName") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("CountryName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="US State">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="ObjectDataSource3" SelectedValue='<%# Bind("StateProvince") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("StateProvince") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<br />

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetMyNames" TypeName="MyName"></asp:ObjectDataSource>
<br />
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetCountryList" TypeName="MyName"></asp:ObjectDataSource>
<br />
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server"
SelectMethod="GetUSStateList" TypeName="MyName"></asp:ObjectDataSource>

</div>
</form>
</body>
</html>


Profile photo
Replied by SBajra
on August 15th, 2012 at 14:45:51 EST
TestPage.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlCountry = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
DropDownList ddlState = (DropDownList)(DetailsView1.FindControl("DropDownList2"));

if (ddlCountry.SelectedValue == "USA")
ddlState.Visible = true;
else
ddlState.Visible = false;
}
}

Profile photo
Replied by SBajra
on August 15th, 2012 at 14:46:49 EST
MyName.cs (This should be inside App_Code folder in ASP.NET. Used for custom data.)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for MyName
/// </summary>
public class MyName
{
private string firstName;

public string FirstName
{
get { return firstName; }
set { firstName = value; }
}

private string lastName;

public string LastName
{
get { return lastName; }
set { lastName = value; }
}

private string countryName;

public string CountryName
{
get { return countryName; }
set { countryName = value; }
}

private string stateProvince;

public string StateProvince
{
get { return stateProvince; }
set { stateProvince = value; }
}


public static List<MyName> GetMyNames()
{
List<MyName> myNames = new List<MyName>();

MyName name1 = new MyName();
name1.FirstName = "Bill";
name1.LastName = "Gates";
name1.CountryName = "USA";
name1.StateProvince = "CA";
myNames.Add(name1);

MyName name2 = new MyName();
name2.FirstName = "John";
name2.LastName = "Smith";
name1.CountryName = "USA";
name1.StateProvince = "NY";
myNames.Add(name2);


return myNames;
}

public static string[] GetCountryList()
{
return new string[3] { "USA", "Canada", "Japan" };
}

public static string[] GetUSStateList()
{
return new string[4] { "CA", "NY", "DC", "OH" };
}
}

Profile photo
Replied by Amvigill
on August 15th, 2012 at 15:35:08 EST
I'm not sure if this is possible, but I dont seem to have or to have the ability to add an App_code folder
Edited on August 15th, 2012 at 15:53:21 EST

Profile photo
Replied by SBajra
on August 15th, 2012 at 15:56:36 EST
The sample I sent is using simple WebSite configuration in Visual Studio.
But seems like you are using web application project. If you are using ASP.NET as Web Application project then you can keep MyName.cs to whatever location under your application (even root).

You may also need to convert TestPage.aspx to Web Application. You can convert to Web application by right clicking on the page and click "Convert to Web Application".

Hope this helps.

Profile photo
Replied by Amvigill
on August 15th, 2012 at 16:20:27 EST
I will try and work alongside this example. Thank you for all of your help.

Profile photo
Replied by SBajra
on August 15th, 2012 at 17:22:50 EST
If this solution helps then please accept the answer.