Peter Chan
asked on
Problem to DDL
Hi,
I see that
Convert.ToString(dt.Rows[0 ]["status_ dscr"])
is having correct DDL value inside, but by these
I see that
Convert.ToString(dt.Rows[0
is having correct DDL value inside, but by these
if (ddlStatus3.Items.FindByValue(Convert.ToString(dt.Rows[0]["status_dscr"])) != null)
ddlStatus3.Items.FindByValue(Convert.ToString(dt.Rows[0]["status_dscr"])).Selected = true;
...
the DDL is not showing correct value on page. why?
ASKER
But
Convert.ToString(dt.Rows[0 ]["status_ dscr"])
is having correct DDL value inside, while ddlStatus3 is also showing a list of that kind of value.
Convert.ToString(dt.Rows[0
is having correct DDL value inside, while ddlStatus3 is also showing a list of that kind of value.
so do you mean the DDL 's item was not selected?
can you tell us:
1. the value of Convert.ToString(dt.Rows[0 ]["status_ dscr"]) ?
2. what's the HTML codes generated from the DDL as the output?
we wish to compare those values together...
can you tell us:
1. the value of Convert.ToString(dt.Rows[0
2. what's the HTML codes generated from the DDL as the output?
we wish to compare those values together...
ASKER
Convert.ToString(dt.Rows[0 ]["status_ dscr"])
is having one value, that is currently one value of the list from DDL. These 2 lines
is having one value, that is currently one value of the list from DDL. These 2 lines
if (ddlStatus3.Items.FindByValue(Convert.ToString(dt.Rows[0]["status_dscr"])) != null)
ddlStatus3.Items.FindByValue(Convert.ToString(dt.Rows[0]["status_dscr"])).Selected = true;
...
are being fired, upon that I press Edit button. But why can't I see the DDL showing the correct value selected?
>>But why can't I see the DDL showing the correct value selected?
Exactly! so that's why I try to give you advise on telling us what's the output generated from your script and then we can diagnose which part causing the "error".
Exactly! so that's why I try to give you advise on telling us what's the output generated from your script and then we can diagnose which part causing the "error".
so do you mean the DDL 's item was not selected?Without providing sufficient info, it's difficult for us to give suggestions/solutions
1. the value of Convert.ToString(dt.Rows[0]["status_ dscr"]) ?
2. what's the HTML codes generated from the DDL as the output?
ASKER
Here is how DDL is being binded
why can't these
Convert.ToString(dt.Rows[0 ]["status_ dscr"])
is having the right value inside.
sql = "select code,dscr from c_status where deleted = '0' and system = 'OK' order by id ";
dt = DBUtil.GetCodeTable(conn, sql);
ddlStatus.DataSource = dt;
ddlStatus.DataValueField = "code";
ddlStatus.DataTextField = "dscr";
ddlStatus.DataBind();
why can't these
ddlStatus3.SelectedIndex = -1;
if (ddlStatus3.Items.FindByValue(Convert.ToString(dt.Rows[0]["status_dscr"])) != null)
ddlStatus3.Items.FindByValue(Convert.ToString(dt.Rows[0]["status_dscr"])).Selected = true;
reveal the correct value to DDL, while I check thatConvert.ToString(dt.Rows[0
is having the right value inside.
since you mentioned:
>> sql = "select code,dscr from c_status where deleted = '0' and system = 'OK' order by id ";
>>ddlStatus.DataValueField = "code";
>>ddlStatus.DataTextField = "dscr";
>>dt.Rows[0]["status_dscr" ]
and you are searching via FindByValue method
is that mean there's a possibility dt.Rows[0]["status_dscr"] will equal to "code" in table: c_status ?
in addition, you may try change:
>> sql = "select code,dscr from c_status where deleted = '0' and system = 'OK' order by id ";
>>ddlStatus.DataValueField
>>ddlStatus.DataTextField = "dscr";
>>dt.Rows[0]["status_dscr"
and you are searching via FindByValue method
is that mean there's a possibility dt.Rows[0]["status_dscr"] will equal to "code" in table: c_status ?
in addition, you may try change:
ddlStatus3.Items.FindByValue
to:ddlStatus3.Items.FindByText
for testing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many many thanks Ryan. It is fine for that DDL.
But it is not for another DDL below.
Here is how I bind it
]["store_d scr"]) is having the correct value (equal to "dscr" that is the binding column)
But it is not for another DDL below.
Here is how I bind it
sql = @"select store_no as code,dscr
from c_store_ok c
where deleted = '0' and dscr is not null and trim(dscr)<>'' order by dscr";
//sql = ConvStoreUtil.GetSqlStoreCode(accessRight, dept);
dt = DBUtil.GetCodeTable(conn, sql);
Session["dtStore"] = dt;
ddlStore_ok.DataSource = dt;
ddlStore_ok.DataValueField = "code";
ddlStore_ok.DataTextField = "dscr";
ddlStore_ok.DataBind();
...
By these below ddlStore.SelectedIndex = -1;
if (ddlStore.Items.FindByText(Convert.ToString(dt.Rows[0]["store_dscr"])) != null)
ddlStore.Items.FindByText(Convert.ToString(dt.Rows[0]["store_dscr"])).Selected = true;
I am not able to show correct value by DDL, even if I've tried FindByValue, while Convert.ToString(dt.Rows[0
>>ddlStore_ok.
>>ddlStore
1. can you tell us which one is not selecting the item?
2. can you post the codes for DataBind() of DDL ddlStore_ok?
just a side quick guess.... is that possible your DDL was being refreshed everytime after the page was posted back?
you may want to consider to put a IsPostBack check before you binding the DDL?
>>ddlStore
1. can you tell us which one is not selecting the item?
2. can you post the codes for DataBind() of DDL ddlStore_ok?
just a side quick guess.... is that possible your DDL was being refreshed everytime after the page was posted back?
you may want to consider to put a IsPostBack check before you binding the DDL?
"status_dscr" looks like a Status Description to me, or do you have some other fields like "status_id" instead that contains the Status Value?
if yes, try change:
Open in new window
to:Open in new window
etc