473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Issue with dropdownlist in a user control

The issue here is -

When the postback event happens the selected index is always returing the
first value.
Appreciate your help in advance.

Thanks

Here is the code
----------------------------------------------------------------------------
--------------------------------------
<%@ Control Language="C#" %>
<%@ import Namespace="goondemand.framework" %>
<%@ import Namespace="goondemand.framework.types" %>
<%@ import Namespace="goondemand.ui.util" %>
<script runat="server">

// public access to class data elements
private String fieldlabel = "";
private String fieldvalue = "";
private String fieldname = "";
private int fieldlength = 0;
private int spacesfromleft = GlobalConfig.SPACESFROMLEFT;
private bool hidelabel = false;
private String align = "left";
private bool colonenabled = false;
private bool required = false;
private String classname = "lookup-default";
private ListData listData;

private String label = "";
public String FIELDNAME{
get{
return fieldname;
}

set{
fieldname=value;
}
}

public String FIELDLABEL{
get{
return fieldlabel;
}

set{
fieldlabel=value;
}
}
public String FIELDVALUE{
get{
return fieldvalue;
}

set{
fieldvalue=value;
}
}
public int FIELDLENGTH{
get{
return fieldlength;
}

set{
fieldlength=value;
}
}

public int SPACESFROMLEFT{
get{
return spacesfromleft;
}

set{
spacesfromleft=value;
}
}
public bool HIDELABEL{
get{
return hidelabel;
}

set{
hidelabel=value;
}
}

public bool COLONENABLED{
get{
return colonenabled;
}

set{
colonenabled=value;
}
}

public String ALIGN{
get{
return align;
}

set{
align=value;
}
}

public bool REQUIRED{
get{
return required;
}

set{
required=value;
}
}

public String CLASSNAME{
get{
return classname;
}

set{
classname=value;
}
}

public ListData LISTDATA{
get{
return listData;
}

set{
listData=value;
}
}

void Page_Load(Object obj, EventArgs args){
localDropDown.ID = fieldname;

if (hidelabel){
label = "";
}
else {
if (required) {
label = GlobalConfig.REQUIRED + "&nbsp;" + fieldlabel;
}
else {
label = fieldlabel;
}

if (colonenabled){
label = label + ":";
}
}

int selectIndex=1;

if (!Page.IsPostBack) {

if (listData != null ){

String field1 = "";
String field2 = "";
ArrayList fields = null;
int i = listData.getCount();

if (i >= 1){
fields =
((RowData)listData.getRowData(1)).getOrderedFields ();
field1 = (String)fields[0];
field2 = (String)fields[1];
}

bool firstRow = false;
int index=0;
ListItemCollection listItem = new ListItemCollection();

for(index = 1;index < i;index++){

RowData singleRow =
(RowData)listData.getRowData(index);

String tempValue1 =
(String)singleRow.getFieldValue(field1);
String tempValue2 =
(String)singleRow.getFieldValue(field2);
if (null == tempValue1){
tempValue1 = "";
}
ListItem oneItem = new
ListItem(tempValue2,tempValue1);
listItem.Add(oneItem);

if ( tempValue1.Equals(FIELDVALUE) ){
selectIndex = index;
}
}

localDropDown.DataSource = listItem;
localDropDown.DataTextField = "text";
localDropDown.DataValueField = "value";
localDropDown.DataBind();
} // end of null != data

} // end of postback

if (Page.IsPostBack){
Log.Instance.write(Log.INFO,this.ToString(),"The selected index
in
the drop down is "+ localDropDown.SelectedValue);
}
} // end of method page_load
public String getStartTag() {

String tag = "<td width=\"100%\" class=\""+ classname + "\">";
tag = tag + System.Environment.NewLine + "<table border=\"0\"
width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">";
tag = tag + System.Environment.NewLine + "<tr>";
tag = tag + System.Environment.NewLine + "<td class=\"" +
classname
+ "\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">" +
Misc.Instance.getSpaces(spacesfromleft) + label + "</td>";
tag = tag + System.Environment.NewLine + "</tr>";
tag = tag + System.Environment.NewLine + "<tr>";
tag = tag + System.Environment.NewLine + "<td class=\"" +
classname
+ "\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">" +
Misc.Instance.getSpaces(spacesfromleft);
return tag;
}

public String getEndTag() {
String tag = "</td>";
tag = tag + System.Environment.NewLine + "</tr>";
tag = tag + System.Environment.NewLine + "</table>";
tag = tag + System.Environment.NewLine + "</td>";
return tag;
}

</script>
<%=getStartTag()%>
<asp:DropDownList id="localDropDown" runat="server"></asp:DropDownList>
<%=getEndTag()%>


Nov 19 '05 #1
0 1003

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
2
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to...
2
by: P. Yanzick | last post by:
Hello, I am creating an edit template for a FormView control, changing one of the textboxes to a dropdown box. The dropdown will be populated from a simple table with the primary key, and a...
1
by: Matt | last post by:
Hi. I'm using VS2005 and working with the Dropdownlist control on an ASP page. My dropdownlist has several thousand items, all integers, ranging from 1000 to 80000 (these represent different...
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.