Hi Priya8,
I have created sample, refer the below code.
HTML
<div>
<asp:DropDownList ID="DropDownList2" runat="server" OnSelectedIndexChanged="GenerateCode"
AutoPostBack="true">
<asp:ListItem Text="Select" Value="0" />
<asp:ListItem Text="HAG01" Value="HAG01" />
<asp:ListItem Text="HEM08" Value="HEM08" />
</asp:DropDownList>
<br />
<asp:TextBox ID="TextBox4" runat="server">
</asp:TextBox>
</div>
Code
private static string hasValue = string.Empty;
private static string hemValue = string.Empty;
protected void GenerateCode(object sender, EventArgs e)
{
string contractNo;
string selected = DropDownList2.SelectedItem.Value;
string code = string.Empty;
if (selected == "HAG01")
{
if (hasValue == string.Empty)
{
contractNo = "1";
code = string.Format("ABC/{0}/{1}/" + contractNo + "/2016-17", selected.Substring(0, 1).Equals("H") ? "HQ" : "RD", selected.Substring(1, 2));
hasValue = code;
}
else
{
contractNo = (Convert.ToInt32(hasValue.Split('/')[3]) + 1).ToString();
code = string.Format("ABC/{0}/{1}/" + contractNo + "/2016-17", selected.Substring(0, 1).Equals("H") ? "HQ" : "RD", selected.Substring(1, 2));
hasValue = code;
}
}
else if (selected == "HEM08")
{
if (hemValue == string.Empty)
{
contractNo = "1";
code = string.Format("ABC/{0}/{1}/" + contractNo + "/2016-17", selected.Substring(0, 1).Equals("H") ? "HQ" : "RD", selected.Substring(1, 2));
hemValue = code;
}
else
{
contractNo = (Convert.ToInt32(hemValue.Split('/')[3]) + 1).ToString();
code = string.Format("ABC/{0}/{1}/" + contractNo + "/2016-17", selected.Substring(0, 1).Equals("H") ? "HQ" : "RD", selected.Substring(1, 2));
hemValue = code;
}
}
TextBox4.Text = code;
}
Screenshot
