locked
How to split string and fill the data controls from database RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    Below is my code to insert some values in database column.

    com.Parameters.AddWithValue("@ID_Proof", ddlIdProof.SelectedItem.Text + " (" + txtIDProff_Number.Text + ")");

    here I am inserting id proof from a dropdownlist along with id proof number through a text box with ().

    when I fetch the string from database to fill the records I am doing like below

    ddlIdProof.SelectedIndex = ddlIdProof.Items.IndexOf(ddlIdProof.Items.FindByText(dt.Rows[0]["ID_Proof"].ToString()));

    My ID_Proof colum in databse  have value like "Adharcard (1234567)". // as I am inserting values by combining the dropdownlist and textbox with ()

    How can I show Adharcard in my dropdownlist and 1234567 in my textbox named txtIDProff_Number.

    Thanks

    Friday, October 14, 2016 4:59 AM

Answers

  • User1724605321 posted

    Hi demoninside9,

    You could split "Adharcard (1234567)" like :

     var test = "Adharcard (1234567)";      
     var output = test.Split('(', ')');

    output[0] will be "Adharcard" , output[1] will be "1234567".

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 14, 2016 6:00 AM

All replies

  • User1724605321 posted

    Hi demoninside9,

    You could split "Adharcard (1234567)" like :

     var test = "Adharcard (1234567)";      
     var output = test.Split('(', ')');

    output[0] will be "Adharcard" , output[1] will be "1234567".

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 14, 2016 6:00 AM
  • User-1716253493 posted
    SELECT LEFT(ID_PROOF, CHARINDEX('(', ID_PROOF)-1) as DataText, ID_PROOF as DataValue

    Friday, October 14, 2016 7:15 AM
  • User1052662409 posted

    output[0] will be "Adharcard" , output[1] will be "1234567".

    shows error

    System.IndexOutOfRangeException: Index was outside the bounds of the array.

    Friday, October 14, 2016 12:16 PM