My question is :
here by i have two dropdownlists both are fetching data from database
i have textboxes also
when i doesnot select value from first dropdownlist then i want value of textbox automatically set to 1.
This is Design page Coding
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="abc.aspx.cs" Inherits="Abhimanu_ADMIN_abc" %>
<!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>
Select Test Type
<asp:DropDownList ID="ddlTestType" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlTestType_SelectedIndexChanged" Width="100px">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtTestType" runat="server"></asp:TextBox>
<br />
Select Test Section
<asp:DropDownList ID="ddlTestSection" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlTestSection_SelectedIndexChanged" Width="140px">
</asp:DropDownList>
<asp:TextBox ID="txtTestSection" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
this is codebehind
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Net;
using System.IO;
public partial class Abhimanu_ADMIN_abc : System.Web.UI.Page
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
//SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["test"].ToString());
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conTestMaster"].ToString());
DataTable dtbladd = new DataTable();
clsAddTest objtest = new clsAddTest();
SqlCommand cmdAd;
//string test;
bool IsPageRefreshed = false;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack == true)
{
dtbladd = objtest.dtTestType();
ddlTestType.Items.Clear();
for (int i = 0; i < dtbladd.Rows.Count; i++)
{
ddlTestType.Items.Add(dtbladd.Rows[i]["TestName"].ToString());
}
ddlTestType.DataSource = dtbladd;
dtbladd = objtest.dtTestSection(Convert.ToInt16(ddlTestType.SelectedIndex.ToString()) + 1);
ddlTestSection.Items.Clear();
for (int i = 0; i < dtbladd.Rows.Count; i++)
{
ddlTestSection.Items.Add(dtbladd.Rows[i]["TestSection"].ToString());
}
ddlTestSection.Items.Insert(0, "----------Select----------");
}
}
protected void ddlTestType_SelectedIndexChanged(object sender, EventArgs e)
{
dtbladd = objtest.dtTestSection(Convert.ToInt16(ddlTestType.SelectedIndex.ToString()) + 1);
ddlTestSection.Items.Clear();
for (int i = 0; i < dtbladd.Rows.Count; i++)
{
ddlTestSection.Items.Add(dtbladd.Rows[i]["TestSection"].ToString());
}
DataTable dt1 = new DataTable();
dt1 = objtest.dtGetTesttypeID(ddlTestType.SelectedItem.Text.ToString());
if (dt1.Rows.Count > 0)
{
ddlTestType.SelectedValue = dt1.Rows[0]["TestName"].ToString();
txtTestType.Text = dt1.Rows[0]["ID"].ToString();
}
}
protected void ddlTestSection_SelectedIndexChanged(object sender, EventArgs e)
{
dtbladd = new DataTable();
dtbladd = objtest.dtGetTestSectionId(ddlTestSection.SelectedItem.Text.ToString());
if (dtbladd.Rows.Count > 0)
{
ddlTestSection.SelectedValue = dtbladd.Rows[0]["TestSection"].ToString();
txtTestSection.Text = dtbladd.Rows[0]["ID"].ToString();
}
}
}