SharePoint dropdown behaviour
-
mercredi 8 août 2012 06:16I've created aspx page in Sharepoint, In it I placed the asp.net dropdown control (drpitems) and I bind the some values to the control. In the aspx page I've another control called button. In run time I've selected some value in dropdown control and rise the button control.
In button control I do the following.
button event
{
ListItem item= drpitems.SelectedItem;
}
the problems is whatever dropdown items i chosen and raise the event the drop down selectded item contain always dropdown first item's value. but normal asp.net web application behave what I expected.If you get your question answered, please come back and mark the reply as an answer.
If you are helped by an answer to someone else's question, please mark it as helpful.
By Sarathi- Type modifié Sarathi R jeudi 23 août 2012 09:17
Toutes les réponses
-
mercredi 8 août 2012 06:46
Hi,
At what stage are you binding the items to the dropdown control? It seems that before your button click event is getting a chance to get fired, the drop down is being re-bound causing it to lose its selecteditem.
Regards
Nauzad Kapadia.
Please "Mark as Answer" if a post has answered your question or "Vote as Helpful" if it was helpful in some way. Here's why
-
mercredi 8 août 2012 09:16
hi Nauzad,
The values bind at page onload event which is one time binded that also at page newly loaded not post back.
If you get your question answered, please come back and mark the reply as an answer.
If you are helped by an answer to someone else's question, please mark it as helpful.
By Sarathi -
mercredi 8 août 2012 09:18
Hi Sarathi,
In your onload event, bind the DropDown control only if its not post back.
Add the bellow code and check if it works
if(!Page.IsPostBack)
{
//Code to bind drop down control
}
Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010
-
mercredi 8 août 2012 09:26
Hi
You need to check in your page OnLoad event whether the page is getting loaded for the first time or getting loaded because of a postback. Even if a page is posted back, the onLoad event of the page will still fire.
Use the IsPostBack property of the page to perform this check.
Regards
Nauzad Kapadia
Please "Mark as Answer" if a post has answered your question or "Vote as Helpful" if it was helpful in some way. Here's why
-
lundi 13 août 2012 11:52I've used the above technique always. eventhought I couldn't get the selected item properly. I'm intermediate level programmer in ASP.NET I never ask simple question in froum first of all.
If you get your question answered, please come back and mark the reply as an answer.
If you are helped by an answer to someone else's question, please mark it as helpful.
By Sarathi -
lundi 13 août 2012 12:07
Hi Sarathi,
Then you need to post your complete source code to allow someone to identify the problem.
Regards,
Nauzad Kapadia.
P.S. There is no fixed definition for what constitutes a simple or difficult question. Solutions are provided to you on the basis of past experience and assumptions of what you COULD have done wrong.
Please "Mark as Answer" if a post has answered your question or "Vote as Helpful" if it was helpful in some way. Here's why
-
lundi 20 août 2012 12:26
Hi Ram,
I always work like what you said. I got the drop down first item always in my button post back event. what is mistake here.
I've dropdown list ( id drplistitem) and in page load method I bind the data like as below
button_event
page load
if(!Page.IsPostBack)
{
LoadDropListItems();
}
private void LoadDropListItems()
{
SPWeb web = SPContext.Current.Web;
string listname = "listname";
SPList lst = web.Lists.TryGetList(listname);
if (listname != null)
{
List<ListfieldDef> flds = new List<ListfieldDef>();
foreach (SPField fld in lst.Fields)
{
if (fld.CanBeDeleted && !fld.Hidden)
flds.Add(new ListfieldDef() { FieldDataType = fld.TypeAsString, FieldFullName = fld.Title });
}
drplistitem.DataSource = flds;
drplistitem.DataTextField = "FieldName";
drplistitem.DataValueField = "FieldType";
drplistitem.DataBind();
}
{
ListItem itm= drplistitem.SelectedItem; //item always first items of dropdown list.
}
public class FieldDetails
{
public string FieldName{get;set;}
public string FieldType{get;set;}
}If you get your question answered, please come back and mark the reply as an answer.
If you are helped by an answer to someone else's question, please mark it as helpful.
By Sarathi

