Hi All,
I have a DropDownList in a content page. i would like to access its selectedvalue my user control page. the below is DDL
<asp:dropdownlist id="ddl1" runat="server" autopostback="true">
<asp:listitem value="6" >6</asp:listitem>
<asp:listitem value="12" >12</asp:listitem>
<asp:listitem value="24">24</asp:listitem>
<asp:listitem value="48">48</asp:listitem>
<asp:listitem value="999">All</asp:listitem>
</asp:dropdownlist>how can i access the ddl1.selectedvalue to my ascx page. i was hoping to do something like
public int contentDDLThanks and i appreciate it
{
get { return Convert.ToInt32( // what should i put here to access the ddl1.selectedvalue); }
set
{
this.Convert.ToInt32( // and here) = value;
}
}
![]() |
0 |
![]() |
public int contentDDL
{
get {DropDownList control = (DropDownList) this.Page.FindControl("DropDownList1");
return Convert.ToInt32( control.SelectedValue); }
set
{
this.Convert.ToInt32( // and here) = value;
}
}
![]() |
0 |
![]() |
Hi,
i changed it to above and i got this error.
public int contentDDL
{
get {
DropDownList dd1control = (DropDownList) this.Page.FindControl("ddl1");
return Convert.ToInt32(dd1control.SelectedValue);
}
set
{
this.Convert.ToInt32(dd1control.SelectedValue); ------------ getting error over here
}
}and the error i am getting is
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0117: 'mycontrol' does not contain a definition for 'Convert'
Source Error:
Line 71: set
Line 72: {
Line 73: this.Convert.ToInt32(dd1control.SelectedValue);
Line 74: }
Line 75: }
Thanks i appreciate it.
![]() |
0 |
![]() |
Hi,
change this:
this.Convert.ToInt32(dd1control.SelectedValue);
to this:
Convert.ToInt32(dd1control.SelectedValue);
Regards,
Segundo Serrano P.
Ing. Sistemas
http://www.4workgroup.com/
Blog: http://dotnet-peru.blogspot.com
![]() |
0 |
![]() |
Hi,
now i am getting this error after changing to Convert.ToInt32(dd1control.SelectedValue);
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'dd1control' does not exist in the current context
Source Error:
Line 72: set
Line 73: {
Line 74: Convert.ToInt32(dd1control.SelectedValue);
Line 75: }
Line 76: }
any advice sir
Thanks
![]() |
0 |
![]() |
Hi,
Summarize:
1.- the dropdownlist is in your page...right?
2.- the user control needs get the value of the dropdownlist... right?
------------------------------------------------------------------------------------------------
//in the user control:
private static int _contentDDL;
public static int contentDDL
{
get { return _contentDDL; }
set
{
_contentDDL = value;
}
}// from you page
MyUserControl.contentDDL = Convert.Toint32(DropDownList1.SelectedValue);
--------------------------------------------------------------------------------------
After that, yo already will have the value of the dropdownlist in the var _contentDDL.
Regards,
Segundo Serrano P.
Ing. Sistemas
http://www.4workgroup.com/
Blog: http://dotnet-peru.blogspot.com
![]() |
0 |
![]() |
Hi Sir,
Thanks that solved it but have one more question sir, now how can i access a particular item selected value. what i mean is
i have this ddl in content page
<asp:dropdownlist id="ddl1" runat="server" autopostback="true">
<asp:listitem value="6" >6</asp:listitem>
<asp:listitem value="12" >12</asp:listitem>
<asp:listitem value="24">24</asp:listitem>
<asp:listitem value="48">48</asp:listitem>
<asp:listitem value="999">All</asp:listitem>
</asp:dropdownlist>now how can i access just the value for <asp:listitem value="999">All</asp:listitem> in my user control page on click of a button. i know selectedvalue will give me what ever i select, but i just want to access just only a particular listitem on a clikck of buttom. hope i am clear in explaining because i can be confusing at times
Thanks i appreciate it
![]() |
0 |
![]() |
Hi,
Based on my understanding, you want to pass a specified item value on the page to the user control.
We can fulfull the task by using the following method according to Sequndo's solution:
MyUserControl.contentDDL = Convert.Toint32(ddl1.Items[4].Value);Have a nice day!
Forward Sun
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |