sujayanand says:
bro I need of substring as dropdownlist ...
Eg: Hi Raju
I want the character before the space in this I need Hi
In your example Hi is first word not a first character.
Instead of using substring you can use Split function to get first word. For substring you always need to specify the end length which will be always different for that you will need to find the length of first word till first space.
So better option you can use Split function. Refer the below example for your reference.
HTML
<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="Select Option" Value="0"></asp:ListItem>
<asp:ListItem Text="Hi Raju" Value="Hi Raju"></asp:ListItem>
<asp:ListItem Text="How are you" Value="How are you"></asp:ListItem>
</asp:DropDownList>
<br />
<br />
First Word: <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
C#
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
string firstWord;
if (ddl.SelectedItem.Value != "0")
{
firstWord = ddl.SelectedItem.Text;
}
else
{
firstWord = string.Empty;
}
this.txtFirstName.Text = firstWord.Trim().Split(' ')[0];
}
Screenshot
