| | |
create sqldatasource through coding
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 85
Reputation:
Solved Threads: 3
•
•
•
•
thnks dude ,,,will go thr tht link n let u know if it wrks for me,,,,
by the way i found a the code tht i wanted finally,,,here it is ,its very simple using only sql data reader,,,here it is
well this works for me,,thnks for all ur helpASP.NET Syntax (Toggle Plain Text)
Dim conn = New SqlConnection("Data Source=(local);Initial Catalog=(databasename);user id=;pwd=;Trusted_Connection=yes") conn.open() Dim dr As SqlDataReader Dim cmd = New SqlCommand("select * from details", conn) dr = cmd.ExecuteReader() DropDownList1.DataSource = dr DropDownList1.DataTextField = "fname" DropDownList1.DataValueField = "srno" DropDownList1.DataBind()
ASP.NET Syntax (Toggle Plain Text)
DropDownList1.DataSource = dr
Johnny.G
Well one way is to loop through the datareader and get the values in each row and add it to dropdownlist.
This involves the following steps.
This involves the following steps.
•
•
•
•
While end of datareader
create list item instance
add fname of row(i) to listitem text
add srid of row(i) to listitem value
add listitem to dropdownlist
end while
Last edited by bala24; Jun 26th, 2008 at 8:05 am.
Michelangelo
"The best place to find a helping hand is at the end of your own arm"
"The best place to find a helping hand is at the end of your own arm"
Do fill in the rest of the details
ASP.NET Syntax (Toggle Plain Text)
Dim li As ListItem If rd.HasRows Then Do While rd.Read li = New ListItem li.Text= rd.Item("fname") li.Value = rd.Item("srid") <dropdownlist>.Items.Add(li) Loop rd.close() End If
Last edited by bala24; Jun 26th, 2008 at 8:39 am.
Michelangelo
"The best place to find a helping hand is at the end of your own arm"
"The best place to find a helping hand is at the end of your own arm"
•
•
Join Date: Feb 2008
Posts: 85
Reputation:
Solved Threads: 3
•
•
•
•
Do fill in the rest of the details
ASP.NET Syntax (Toggle Plain Text)
Dim li As ListItem If rd.HasRows Then Do While rd.Read li = New ListItem li.Text= rd.Item("fname") li.Value = rd.Item("srid") <dropdownlist>.Items.Add(li) Loop rd.close() End If
thnks 1ce again
Johnny.G
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
ASP.NET Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlDataSource mySource = new SqlDataSource("Data Source=SERKAN\\MYSQLSERVER2005;Initial Catalog=deneme;Integrated Security=True;Pooling=False", "select * from names"); myDropDown.DataSource = mySource.Select(DataSourceSelectArguments.Empty); myDropDown.DataValueField = "PKID"; myDropDown.DataTextField = "name"; myDropDown.DataBind(); } }
This is a great sample. I've been searching google for an hour to find a good sample for creating a sqldatasource in a class. Thank you!!
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Load image in report in runtime in ASP.Net
- Next Thread: ASP.net - Flash Postback problem : Please Help
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances application asp asp.net beginner box browser businesslogiclayer button c# cac checkbox child class compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form gridview gudi iis image javascript list listbox menu mouse mssql nameisnotdeclared news novell numerical opera order parent problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security select serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview typeof validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xsl





