i have one function whch is used for databinding to dropdown list.but on one page there are many dropdownlists so it crete writing same code for every dropdownlist with its name only diffrent.so i want to know how can i pass diffrent dropdownlist names to
single function using a variable which can take dropdownlist name as variable.in short i want to use same function for siffrent dropdownlists.
Instead of Passing the name of the dropdown, pass the control to the function and in that function directly do the databinding. By this approach there is no need of passing the name of control.
(This below is sample example only for understanding puposes)
For eg
Function BindDropDown( ddState System.webcontrols.dropdownlist )
thank u for ur mail i need in asp.net with vb.net, i tried my own i don't no how to pass dropdownlist as parameter in function pls guid me
Public Function kannan(ByRef Drop As WebControls.DropDownList, ByRef dset As Data.DataSet, ByVal tabname As String, ByVal textfield As String, ByVal valueField As String)
Drop.DataSource = dset
Drop.DataValueField = dset.Tables(tabname).Columns(valueField).ToString()
Drop.DataTextField = dset.Tables(tabname).Columns(textfield).ToString()
Drop.DataBind()
End Function
sansat6699
Member
30 Points
72 Posts
passing dropdownlist name (any asp.net control) to single function
Oct 08, 2007 08:28 AM|LINK
hi
i have one function whch is used for databinding to dropdown list.but on one page there are many dropdownlists so it crete writing same code for every dropdownlist with its name only diffrent.so i want to know how can i pass diffrent dropdownlist names to single function using a variable which can take dropdownlist name as variable.in short i want to use same function for siffrent dropdownlists.
i am using asp.net 2.0
thank you
asp 2.0 using varible for control names
CDERUE
Member
214 Points
42 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Oct 08, 2007 08:55 AM|LINK
Hi,
What is your code actually plz ?
impathan
Contributor
4371 Points
836 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Oct 08, 2007 09:06 AM|LINK
You can identify control using sender argument.
like as
public function values() { string DropDownList_ID=((DropDownList)sender).ID; }ImranKhan pathan
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Oct 08, 2007 09:15 AM|LINK
Hi,
try below one...
fucntion fillDropdown(DropdownList ddl)
{
ddl.datasource = .......;
ddl.databind();
}
You can call this method as below,
fillDropdown(dropdown which you wnat to fill);
I hope this will help you.....
Software Engineer.
Suhas.Chitad...
Member
140 Points
25 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Oct 08, 2007 09:44 AM|LINK
Instead of Passing the name of the dropdown, pass the control to the function and in that function directly do the databinding. By this approach there is no need of passing the name of control.
(This below is sample example only for understanding puposes)
For eg
Function BindDropDown( ddState System.webcontrols.dropdownlist )
{ ddState.DataBind();
}
Suhas Chitade
Kannandesika...
Member
368 Points
764 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Nov 14, 2007 05:02 AM|LINK
hi vasanth,
i try this but its not working pls i wants to do to put in a comman function
bcz i have lot of dropdownlist its better for me to put as a comman function
Regards
Kannan.D
drop down list box
Kannandesikan
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Nov 14, 2007 05:17 AM|LINK
Hi,
can you specify some details for your requirement?
Software Engineer.
Kannandesika...
Member
368 Points
764 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Nov 15, 2007 06:20 AM|LINK
Hi vasanth thankx for your mail
see iam using vb.net with asp.net 2.0
If Page.IsPostBack = False Then
dt = obj.ReadTables(strsql)
drpcategory.DataSource = dt.Tables(0)
drpcategory.DataTextField = dt.Tables(0).Columns(1).ToString
drpcategory.DataValueField = dt.Tables(0).Columns(0).ToString
drpcategory.DataBind()
End If
i wants to create comman function in class that i just want to pass dropdownlist as a parament in that function
re dropdownlist doubt
Kannandesikan
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Nov 15, 2007 07:41 AM|LINK
Hi,
try the below one....
public void CompanyToCopy(DropDownList dl, DataSet ds, string tabName, string textFiled, string valueFiled)
{
dl.DataSource = ds;
dl.DataValueField = ds.Tables[tabName].Columns[valueField].ToString();
dl.DataTextField = genericDS.Tables[tabName].Columns[textFiled].ToString();
dl.DataBind();
}
Software Engineer.
Kannandesika...
Member
368 Points
764 Posts
Re: passing dropdownlist name (any asp.net control) to single function
Nov 15, 2007 09:54 AM|LINK
hi vasanth,
thank u for ur mail i need in asp.net with vb.net, i tried my own i don't no how to pass dropdownlist as parameter in function pls guid me
Public Function kannan(ByRef Drop As WebControls.DropDownList, ByRef dset As Data.DataSet, ByVal tabname As String, ByVal textfield As String, ByVal valueField As String)
Drop.DataSource = dset
Drop.DataValueField = dset.Tables(tabname).Columns(valueField).ToString()
Drop.DataTextField = dset.Tables(tabname).Columns(textfield).ToString()
Drop.DataBind()
End Function
Kannandesikan