Answered by:
show gridview data to dropdownlist

Question
-
User-1447786422 posted
I have a grid view with value (date of birth), and some dropdown list (day,month,year). Now i want that when i select a row in my gridview my date of birth split in 3 and fill the dropdownlist
Example:
In my grid view i have a date: 05/06/2018
When i click select my dropdownlist will apear:
Day:05 Month:06 Year:2018
Can any one help me
//My select button protected void lnk_OnClick(object sender, EventArgs e) { int StuID= Convert.ToInt32((sender as LinkButton).CommandArgument); if (sqlCon.State == ConnectionState.Closed) sqlCon.Open(); SqlDataAdapter sqlDa = new SqlDataAdapter("SelectByID", sqlCon); sqlDa.SelectCommand.CommandType = CommandType.StoredProcedure; sqlDa.SelectCommand.Parameters.AddWithValue("@StuID", StuID); DataTable dtbl = new DataTable(); sqlDa.Fill(dtbl); sqlCon.Close(); hfSinhVien.Value = StuID.ToString(); txtHoDem.Text = dtbl.Rows[0]["HoDem"].ToString(); txtTen.Text = dtbl.Rows[0]["Ten"].ToString(); //This is the place where those dropdownlist are txtQueQuan.Text = dtbl.Rows[0]["QueQuan"].ToString(); txtSDT.Text = dtbl.Rows[0]["SDT"].ToString(); txtEmail.Text = dtbl.Rows[0]["Email"].ToString(); ddlLop.SelectedItem.Value = dtbl.Rows[0]["Malop"].ToString(); btnSave.Text = "Update"; btnDelete.Enabled = true; }
Tuesday, July 31, 2018 3:26 AM
Answers
-
-
User-369506445 posted
based on your <g class="gr_ gr_27 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="27" data-gr-id="27">code <g class="gr_ gr_26 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" id="26" data-gr-id="26">,</g></g><g class="gr_ gr_26 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style replaceWithoutSep" id="26" data-gr-id="26">I</g> think you get your date from <g class="gr_ gr_55 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="55" data-gr-id="55">sql</g> in this line
ddlLop.SelectedItem.Value = dtbl.Rows[0]["Malop"].ToString();
if yes you can use
string str = dtbl.Rows[0]["Malop"].ToString() var arr = str.Split('/'); string newValue = String.Format("Day:{0} Month:{1} Year:{2}", arr[0],arr[1],arr[2]); ddlLop.SelectedItem.Text = newValue ;
or with 3 <g class="gr_ gr_129 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="129" data-gr-id="129">drop</g> down
string str = dtbl.Rows[0]["Malop"].ToString() var arr = str.Split('/'); string day = arr[0]; string month = arr[0]; string year = arr[0]; ddlDay.SelectedItem.Text = day; ddlMonth.SelectedItem.Text = month; ddlYear.SelectedItem.Text = year;
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 31, 2018 7:24 AM
All replies
-
User-369506445 posted
hi
<g class="gr_ gr_7 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="7" data-gr-id="7">i</g> create a sample that you can put your date instead of my hardCode date
string str = "05/06/2018"; //hardcode date var arr = str.Split('/'); string newValue = String.Format("Day:{0} Month:{1} Year:{2}", arr[0],arr[1],arr[2]); ddlLop.SelectedItem.Text = newValue ;
Tuesday, July 31, 2018 5:14 AM -
User-1447786422 posted
the problem is i have 3 dropdownlist that separate into day, month, year and i don't know how to present it
Tuesday, July 31, 2018 6:29 AM -
User-369506445 posted
you can define 3 <g class="gr_ gr_23 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="23" data-gr-id="23">dropdown</g> and bind them below
string str = "05/06/2018"; //hardcode date var arr = str.Split('/'); string day = arr[0]; string month = arr[0]; string year = arr[0]; ddlDay.SelectedItem.Text = day; ddlMonth.SelectedItem.Text = month; ddlYear.SelectedItem.Text = year;
Tuesday, July 31, 2018 6:32 AM -
User-1447786422 posted
I'm new to this so can i ask what string i have to put in this " "
my gridviewdata is bind with sqlserver
string str = " ";
Tuesday, July 31, 2018 6:52 AM -
-
User-369506445 posted
based on your <g class="gr_ gr_27 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="27" data-gr-id="27">code <g class="gr_ gr_26 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" id="26" data-gr-id="26">,</g></g><g class="gr_ gr_26 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style replaceWithoutSep" id="26" data-gr-id="26">I</g> think you get your date from <g class="gr_ gr_55 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="55" data-gr-id="55">sql</g> in this line
ddlLop.SelectedItem.Value = dtbl.Rows[0]["Malop"].ToString();
if yes you can use
string str = dtbl.Rows[0]["Malop"].ToString() var arr = str.Split('/'); string newValue = String.Format("Day:{0} Month:{1} Year:{2}", arr[0],arr[1],arr[2]); ddlLop.SelectedItem.Text = newValue ;
or with 3 <g class="gr_ gr_129 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="129" data-gr-id="129">drop</g> down
string str = dtbl.Rows[0]["Malop"].ToString() var arr = str.Split('/'); string day = arr[0]; string month = arr[0]; string year = arr[0]; ddlDay.SelectedItem.Text = day; ddlMonth.SelectedItem.Text = month; ddlYear.SelectedItem.Text = year;
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 31, 2018 7:24 AM -
User-1447786422 posted
Thank u very much, it work perfectly
Tuesday, July 31, 2018 7:34 AM -
User-1447786422 posted
Thank u for your suggestion
Tuesday, July 31, 2018 7:35 AM -
User-1447786422 posted
Can i have your email, need to ask some question?
Tuesday, July 31, 2018 9:29 AM -
User-158764254 posted
Can i have your email, need to ask some question?
The discussions in these forums are all intended to be public. This is so that many developers might benefit from being able to view the difficulties and solutions that other developers have contributed here. If you were to take the discussion offline into emails, if would be counter to one of the goals of these public forums (public discussions).
I'm glad to see that the question that started this thread was sorted/solved for you. Please don't hesitate to start another thread if you have an additional question(s). The members that helped you out in this thread will no doubt see it and respond if they are able.
Wednesday, August 1, 2018 12:47 AM