Gridview Editing for Binded Dropdownlist

Posted by Saritha.rajeshkumar under C# on 8/3/2011 | Points: 10 | Views : 1370 | Status : [Member] | Replies : 3
Hi this is saritha,

iam having a gridview, when i click edit button iam not able to retreive the value in Binded dropdownlist,

my code is

dr = ds.Tables[0].Rows[0];
TxtModelName.Text = dr[0].ToString();
TxtStreet.Text = dr[1].ToString();


ListItem li = DdlCountry.Items.FindByText(dr[2].ToString());
if (li != null)
{
li.Selected = true;
}

ListItem li1 = DdlState.Items.FindByText(dr[3].ToString());
if (li1 != null)
{
li1.Selected = true;
}

ListItem li2 = DdlCity.Items.FindByText(dr[4].ToString());
if (li2 != null)
{
li2.Selected = true;
}
//DdlState.Text = dr[3].ToString();
//DdlCity.Text = dr[4].ToString();
TxtPincode.Text = dr[5].ToString();
TxtPhoneno1.Text = dr[6].ToString();
TxtPhoneno2.Text = dr[7].ToString();




Responses

Posted by: Kshah on: 8/3/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Saritha

you can try binding it as
1st option: ddlState.SelectedValue = //your datasource (Use this code if your binding value)
2nd option: ddlState.SelectedItem.Text = //your datasource (Use this code if your binding Text)

Thanks & Regards,
Komal Shah

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 8/3/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

You can do this way...

ddlState.Items.FindByValue(dr[4].ToString()).Selected = true;



Thanks and Regards
Madhu

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 8/6/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi saritha,

First of all checked wheather this drop-down list has items.

i means to say, when u select listitem by text and then u check that listitem is not null then select ok?

i think u didn't get listitem from that method, n that's why ur functionality is not working properly.

Mark If this answer help you.

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response