so let me make sure im understanding you right. the ddl that i am referring to is one that will be populated with whatever is in the database for that field when all fillprojectfields method is called.. this is not the original ddl where they select the
project to populate..
so let me make sure im understanding you right. the ddl that i am referring to is one that will be populated with whatever is in the database for that field when all fillprojectfields method is called.. this is not the original ddl where they select the project
to populate..
I'm confused here.. What exactly you are trying to do?
sorry. I have a page that has a handfull of textboxes, dropdownlists, radiobuttons and checkboxlists. at the top i have a dropdownlist of ProjectNames. when the user selcts a projectname from the dropdownlist, i am trying to have the rest of the fields populated
based on that selection. make sense?
Yes i understand but you cannot assign SelectedValue and SelectedItem.Tex on DDL and RBL you need to use Items.Add method to add items on DDL and RBL based on DDL from ProjectNames... see below..
private void FillDT(string ProjectName)
{
SqlConnection conn = new SqlConnection(strCon);
conn.Open();
string sql = "select * from TableName where ProjectName='"+ProjectName+"'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
TextBox1.Text= dt.Rows[0]["ColumnName1"].TosTring(); //Where column name us the Fields for your Table that you wanted to display in the TextBoxes
TextBox2.Text= dt.Rows[0]["ColumnName2"].TosTring();
DropDownList1.Items.Add(dt.Rows[0]["ColumnName3"].TosTring());
RadioButtonList1.Items.Add(dt.Rows[0]["ColumnName4"].TosTring());
CheckBoxList1.Items.Add(dt.Rows[0]["ColumnName5"].TosTring());
}
conn.Close();
The textboxes fill, but the ddl's dont display what should be displayed from the database, they just look like im adding a new project "Please Choose". any suggestions?
The textboxes fill, but the ddl's dont display what should be displayed from the database, they just look like im adding a new project "Please Choose". any suggestions?
Post your codes here so that we can check it out... BTW does your DDL contains multiple data?if you only want to add a single value from database then use TextBox instead..
Here is my code so far. i have got everything to work except one part. In the database that this project is pulled by there is a checkboxlist (names of people working on project) when the project is initially stored, it stores all the checkboxes that are
checked as numbers in a string. what i would like to do is on the update page (code below) i want to comapare the checkboxlist against the database values adn then make the appropriate checkboxes in the list be checked or not checked according to whats in
the database. Heres an example of how thenames are stored as a sting in the database
column name = AssignedMemebers
CheckboxList = cblAssignedMembers
raw data in database = 2, 4, 5, 6 numbers represent different checkboxes(names) checked in the cbl.
Here is my update code so far. everything works now except the cblAssignedMembers
SqlConnection conn =
new SqlConnection(Conn.CLNXCnnString());
conn.Open();
string sql = "select * from tblAddProject where ProjectName='" + strProjectName +
"'";
SqlCommand cmd =
new SqlCommand(sql, conn);
SqlDataAdapter da =
new SqlDataAdapter(cmd);DataTable dt =
new DataTable();
I'm not sure if this is really what you need but i hope this will give you an idea
Put this snippet below after conn.Close();
for (int i=0; i <cblMembersAssigned.Items.Count; i++)
{
if (cblMembersAssigned.Items[i].Text = "Values to compare here")
{
if it's equal then check the items in the CHeckBox
cblMembersAssigned.Items[i].Selected = true;
}
}
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 20, 2008 09:14 PM|LINK
so let me make sure im understanding you right. the ddl that i am referring to is one that will be populated with whatever is in the database for that field when all fillprojectfields method is called.. this is not the original ddl where they select the project to populate..
vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Populate fields from dropdown selection
Jun 20, 2008 09:21 PM|LINK
I'm confused here.. What exactly you are trying to do?
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 20, 2008 09:28 PM|LINK
sorry. I have a page that has a handfull of textboxes, dropdownlists, radiobuttons and checkboxlists. at the top i have a dropdownlist of ProjectNames. when the user selcts a projectname from the dropdownlist, i am trying to have the rest of the fields populated based on that selection. make sense?
vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Populate fields from dropdown selection
Jun 20, 2008 09:48 PM|LINK
Yes i understand but you cannot assign SelectedValue and SelectedItem.Tex on DDL and RBL you need to use Items.Add method to add items on DDL and RBL based on DDL from ProjectNames... see below..
private void FillDT(string ProjectName)
{
SqlConnection conn = new SqlConnection(strCon);
conn.Open();
string sql = "select * from TableName where ProjectName='"+ProjectName+"'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
TextBox1.Text= dt.Rows[0]["ColumnName1"].TosTring(); //Where column name us the Fields for your Table that you wanted to display in the TextBoxes
TextBox2.Text= dt.Rows[0]["ColumnName2"].TosTring();
DropDownList1.Items.Add(dt.Rows[0]["ColumnName3"].TosTring());
RadioButtonList1.Items.Add(dt.Rows[0]["ColumnName4"].TosTring());
CheckBoxList1.Items.Add(dt.Rows[0]["ColumnName5"].TosTring());
}
conn.Close();
}
protected void ddlSearch_SelectedIndexChanged(object sender, EventArgs e){
FillDT(DropDownList1.SelectedValue);
}
Did you get it?
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 04:08 PM|LINK
Hey Vincent,
The textboxes fill, but the ddl's dont display what should be displayed from the database, they just look like im adding a new project "Please Choose". any suggestions?
vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Populate fields from dropdown selection
Jun 23, 2008 05:03 PM|LINK
Post your codes here so that we can check it out... BTW does your DDL contains multiple data?if you only want to add a single value from database then use TextBox instead..
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 08:23 PM|LINK
Here is my code so far. i have got everything to work except one part. In the database that this project is pulled by there is a checkboxlist (names of people working on project) when the project is initially stored, it stores all the checkboxes that are checked as numbers in a string. what i would like to do is on the update page (code below) i want to comapare the checkboxlist against the database values adn then make the appropriate checkboxes in the list be checked or not checked according to whats in the database. Heres an example of how thenames are stored as a sting in the database
column name = AssignedMemebers
CheckboxList = cblAssignedMembers
raw data in database = 2, 4, 5, 6 numbers represent different checkboxes(names) checked in the cbl.
Here is my update code so far. everything works now except the cblAssignedMembers
Thanks
protected void ddlSearch_SelectedIndexChanged(object sender, EventArgs e){
FillProjectFields(ddlSearch.SelectedValue);
}
private void FillProjectFields(string strProjectName){
SqlConnection conn = new SqlConnection(Conn.CLNXCnnString());conn.Open();
string sql = "select * from tblAddProject where ProjectName='" + strProjectName + "'"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter da = new SqlDataAdapter(cmd);DataTable dt = new DataTable();da.Fill(dt);
if (dt.Rows.Count > 0){
txtDate.Text = dt.Rows[0][
"RequestDate"].ToString(); txtChangeUser.Text = dt.Rows[0]["NTLogin"].ToString();txtProjectName.Text = dt.Rows[0][
"ProjectName"].ToString(); txtProjectDesc.Text = dt.Rows[0]["ProjectDesc"].ToString();ddlOccurrence.Items.Add(dt.Rows[0][
"Occurrence"].ToString()); if(dt.Rows[0]["Occurrence"].ToString() == "Reoccurring"){
ddlOccurrence.SelectedValue = "Reoccurring";}
else if (dt.Rows[0]["Occurrence"].ToString() == "One Time"){
ddlOccurrence.SelectedValue = "One Time";}
rblOccurrance.Items.Add(dt.Rows[0]["Automated"].ToString());rblOccurrance.Items.Add(dt.Rows[0][
"Manual"].ToString()); ddlStatus.Items.Add(dt.Rows[0]["StatusName"].ToString());if (dt.Rows[0]["StatusName"].ToString() == "New"){
ddlStatus.SelectedValue = "New";}
else if (dt.Rows[0]["StatusName"].ToString() == "Assigned"){
ddlStatus.SelectedValue = "Assigned";}
else if (dt.Rows[0]["StatusName"].ToString() == "Complete"){
ddlStatus.SelectedValue = "Complete";}
cblMembersAssigned.Items.Add(dt.Rows[0][
"AssignedMembers"].ToString()); txtCompletionDate.Text = dt.Rows[0]["CompletionDate"].ToString();}
conn.Close();
}
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 08:23 PM|LINK
vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Populate fields from dropdown selection
Jun 23, 2008 08:48 PM|LINK
I'm not sure if this is really what you need but i hope this will give you an idea
Put this snippet below after conn.Close();for (int i=0; i <cblMembersAssigned.Items.Count; i++)
{
if (cblMembersAssigned.Items[i].Text = "Values to compare here")
{
if it's equal then check the items in the CHeckBox
cblMembersAssigned.Items[i].Selected = true;
}
}
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 08:52 PM|LINK
where it says "Values to compare here" in that string can i put "1, 2, 3, 4, 5, 6"??