Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all,


Todays my question is,

There is a dropdownlist populate by datatable.
after populating, i have to get and set the default value by finding the item name...(like find the item is MCP what i populated in dropdown). based on the default value i have to show the grid view ... so this is my condition in my task .. pls help me out
Posted
Comments
Richard C Bishop 19-Apr-13 12:36pm    
Not a question.
ZurdoDev 19-Apr-13 13:04pm    
DropDownList has a FindItemByValue method.

Here comes your solution

C#
//datatable here is the collection of data from which u want to select MCP

for(int i=0;i<=datatable.Rows.Count-1;i++)
{

if(datatable.items[i].Text=="MCP")
{
dropDown1.selectedIndex=i;
break;
}
}



Hope it solves your problem.....
 
Share this answer
 
Comments
leosang 20-Apr-13 8:45am    
i got index value by finding the item like mcp,but now i want to get value of that mcp item and pass it that value to another method to get corressponding datas in gridview.

actually i need value of that mcp while populating the ddropdownlist itself. based on that value i can bind the gridview datas...
Raj Parashar 20-Apr-13 12:34pm    
so just use "str=dropdown1.selectedItem.Value" and you are on......
Hello leosang

Why are you using the item name instead of Selected Item Value?, remember that one thing is what our clients see, far away from what we see.

please take a look at this:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist.aspx[^]
Look for:
DataSourceID
DataTextField
DataValueField

Use this to play with your grid view:
Dim ListItemVariable as ListItem = DropDownList1.Items.FindByValue("YourValue")


Dim ValueVariable as object
DropDownList1.SelectedValue = ValueVariable;


Reference for gridview:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx[^]

You could use a single gridview and change the data source or multiple gridviews and show/hide anytime you want.

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900