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 int currentNumber = 1;
public static string GetNextNumber()
{
currentNumber++;
return currentNumber.ToString();
}
protected void GenerateCode(object sender, EventArgs e)
{
string ContractNo;
string selected = DropDownList2.SelectedItem.Value;
string code = string.Empty;
if (selected == "HAG01")
{
ContractNo = GetNextNumber();
code = string.Format("ABC/{0}/{1}/" + ContractNo + "/2016-17", selected.Substring(0, 1).Equals("H") ? "HQ" : "RD", selected.Substring(1, 2));
}
else if (selected == "HEM08")
{
ContractNo = GetNextNumber();
code = string.Format("ABC/{0}/{1}/" + ContractNo + "/2016-17", selected.Substring(0, 1).Equals("H") ? "HQ" : "RD", selected.Substring(1, 2));
}
TextBox4.Text = code;
}
Screenshot