Give the string Metal_In I have to extract the Metal part
I'm doing the following now:
DropDownList ddl = ctrl as DropDownList;
if(ddl != null)
{
ddl.ID = ddl.ID.Split('_')[1].ToString();
}
Give the string Metal_In I have to extract the Metal part
I'm doing the following now:
DropDownList ddl = ctrl as DropDownList;
if(ddl != null)
{
ddl.ID = ddl.ID.Split('_')[1].ToString();
}
instead of index 1 use index 0 (it can be done in a better way). Also you don't need ToString at the end as it is already a string.
dl.ID = ddl.ID.Split('_')[0].ToString();
You may check for array length before using index and .ToString
string[] tempArray = ddl.ID.Split('_');
if(tempArray.Length > 0)
ddl.ID = tempArray[0];
ddl.ID.Split('_')[1] will give you the 2nd part of the string which is In. Remember the array index starts with 0