.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

accessing values from a database with datalist?

Posted By:      Posted Date: August 25, 2010    Points: 0   Category :ASP.Net

I have a datalist and I am filling it using a dataadapter, dataset. So in my .ascx page, I have

<asp:datalist runat="server" id="dlProducts" repeatcolumns="2" repeatdirection="horizontal">


<table border="0">

<tr><td><%# Eval("Item_Name") %></td></tr>

<tr><td>I have to add a picture here</td><td><%# Eval("First_Name") %></td></tr>




In the area where I have put a statement like "I have to add a picture here", I have write a big case statement.  Like:

Case: 6 // show a picture from file1

case: 7 // show a picture from file2

Case 8: //show a picture from file3


So How do I do this here?  Because I dont know how to access the datalist values from code behind.


Here is my code behind:

SQLString = "SELECT First_Name, Picture, item_name, item_id from table1 where item_id = " + request.querystring["iid"];

dataadapter daItems = new dataadapter(SQLString, "connection_name");

dataset dsItems = new dataset();



View Complete Post

More Related Resource Links

Help with updating database with values from Repeater control using c#


Hello, I'm new to ASP.NET 3.5 with C#. I really need some help.

I used a Repeater control to create a simple (editable) list where, when a user logs in, they can edit their list of expenses.  The ASP page works fine.

 My issue is with the code-behind.  I am really confused with how to extract the values from the repeater control. The FindControl method does not seem to be working.  Also, the code I am using resets my 'Amount' values back to 0.00. (0.00 is the amount the user sees when they first encounter the page).

 Here's a portion of the code on the ASP page:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"





<td><asp:Label ID="lblExpId" runat="server"  Text='<%# Bind("ExpId") %>'></asp:Label> </td>

 <td><asp:Textbox ID="lblExpense" runat="server" Width= "190px" Text='<%# Bind("ExpenseName") %>'></asp:Textbox> </td>

 <td><asp:Textbox ID="txtAmount" runat="server" Width= "100px"

How to stored values 10.57 into database



I have the variable value 10.57
10.57 If I write, it stores data: 1057.00

 I need 10.57 into database


Accessing a row's dropdownlist values AFTER the gridview control is in Edit mode

Hello, I have a gridview control. When it goes into Edit mode, there are 3 dropdownlists in one cell that are populated by separate stored procedures during the RowDataBound event. The 1st dropdownlist's value is used as a parameter to determine what the 2nd dropdownlist is populated with. The 2nd dropdownlist's value is used as a parameter to determine what the 3rd dropdownlist is populated with. Everything works fine when the row is first put into Edit mode. While I'm in Edit mode and I change the selection in the 1st dropdownlist, how do I access the control so I can feed this new parameter to the 2nd dropdownlist? I have the first 2 dropdownlists set for AutoPostBack so that the Page_Load event is fired when the user changes a value. I know how to get access to these controls via the FindControl method when the row is being databound but how do I find the control during the Page_Load event? Thanks for any help!!!   Penny  

Writing values back to a database

Hi All, I'm trying to write values back to an access database from an open source mathematical programming language (called glpk) using ODBC. I succeeded in doing so in most variables except one. The problem is described below: The following code gets an error when writing the data: \begin code:   table x3_iii {j in TF, k in C, p in P, t in T: x3[j,k,p,t]>0} OUT 'ODBC'   'FileDSN=.\d2.dsn'   'UPDATE ((Channels a INNER JOIN ChannelPeriodProducts b' 'ON a.ChannelID = b.ChannelID)' 'INNER JOIN TransformerTypes d' 'on a.OriginFacilityID = d.FacilityID' 'SET b.Quantity = ?'   'WHERE d.TransformerTypeID = ?'   'AND a.OriginFacilityID =?'   '    AND b.ProductID = ?'   '    AND b.PeriodID = ?':   x3[j, k, p, t], j, k, p, t; \end code Note that the sql is on multiple lines, because of a maximum strings limit in the glpk (but the way I used in the code is fine and worked without problems for writing other variables). Now, let me describe what I am basically trying to do: I'm trying to write the values for the variable x3[j,k,p,t] in its field "Quantity" in the table 'ChannelPeriodProducts'. The indices for that variable are j,k,p,t. The 'ChannelPeriodProducts' table has a "ChannelID", "PeriodID", "ProductID" and "Quantity" field

Accessing a database

I have added a folder called "Databse" in my application and inside that i have a databse file(SQL Databse named dbFiles), and my connection string looks like this : < add name="conString" connectionString="Data Source=localhost;database=dbFiles;Persist Security Info=True;"/> Now my problem is i am unable to open a connection to this database. What am i doing wrong????

Accessing database in STANDBY mode while log shipping

Hi,     I am testing with Log shipping, I have it setup and it is working just fine. The secondary database was restored with Standby mode and is readonly. I have no problem accessing and querying data from the secondary database but I noticed if changes are made to the primary and I am accessing the database when the restore step to the secondary runs it fails with the following error: Message2006-07-31 09:40:54.33 *** Error: Could not apply log backup file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\LogShip\CI_REPLICATION_TEST_20060731131501.trn' to secondary database 'CI_REPLICATION_TEST'.(Microsoft.SqlServer.Management.LogShipping) ***2006-07-31 09:40:54.33 *** Error: Exclusive access could not be obtained because the database is in use.RESTORE LOG is terminating abnormally.(.Net SqlClient Data Provider) *** This appears to be because you can not restore to a database that is in use? How do you get around this? Is it possible? How do I query data from the secondary db without worrying about causing log shipping to fail? Do I not worry about it because at somepoint when Exclusive access is obtainable all the logs will be rolled forward, but this could create a wide gap in sychronization between the primary and secondary db's, say if someone or something does not properly log off. I guess I could disconnect all users prior to applying tlogs but that kind

Save temporary values in gridview to database

Hi.I have a code here,where it will store temporary data in a gridview from textbox where when the data is stored temporarily in gridview.Alternately,it will be linked to search the word in google.Now i want to save the values in the gridview to database.I m new to asp.net,seeking ideas from all.Any ideas guys?Here is my .aspx code: <body> <div> <table > <tr> <td class="style1"> <asp:Label ID="Label1" runat="server" Text="Caller Info :"></asp:Label> </td> <td style="width: 100px"> <asp:TextBox ID="TxtName" runat="server" class="cls" onekeypress="" ToolTip="Press Enter key for new input"></asp:TextBox> </td> </tr> </table> <asp:Button ID="BtnAddToTable" runat="server" align="right" class="cls" Text="Add" OnClick="BtnAddToTable_Click" /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" > <Columns> <asp:TemplateField HeaderText="Caller Information"> <ItemTemplate> <a onclick='document.getElementById("<%=iframe1.ClientID%>").src = this.href; return false

How to retrive client name ,Field , and Image from Database and show in datalist?


hi experts,

i wanat to display Client Name, Field and  image in datalist. Stored Procedure like this

ALTER proc [dbo].[get_clients_services]
SELECT     Clients.ClientName AS Client, Fields.FieldName AS Field, ServiceType.ServiceType AS Services, ServiceType.Servicelink AS Link, 
                      Clients.ClientLogo AS Logo
FROM         Clients INNER JOIN

Accessing the same database many people at once


I there.

 I made a website, 1 database;  We have 4 cumputers, the 4 are using the same website and saving datas at the SAME TIME.

 The problem that i have is that when 2 people click in the save button at the same time, only onces is in the database, but the others get lost.


 Visual Studio 2010, Framework 3.5, MS-SQL 2008, C#.

 The conecction is in c#, everthing is in c#.





Accessing my Web Application's database with MSSMS at the same time.



I wish to acces my database using MSSMS at the same time that I am running my web application. When I tried to access my database with MSSMS I get the following error:

Failed to retrieve data for this request (Microsoft.SqlServer. Management.SDk.Sfc)

Additional Information:

Unable to open the physical file "C:\inetpub\wwwroot\myapp\App_Data\aspnetdb.mdf".
Operationg system error 32: "32(The process cannot access the file because it is being used by another process)". (Microsoft SQL Server, Error:5120).

What can I do to being able to view my database with MSSMS at the same time?

Thanks for your help,


Get list of Correlation Key Values from Database


I want to know from the the Sql database (workflow persisted) how I can get a list of the unique ids I have correlating to the workflows started.  I have no problem getting the system generated Workflow Instance Id GUIDs, however I want to display our OrderId instead.

My Info

-Using Workflow 4.0

-Workflows are getting persisted to database

-correlation handle is set to my unique Id (OrderId) in the ReceiveActivity

Assigning values from a Database to a Label



I want to select all the values from a table in my database and then put each value in order into labels that are on the asp page.

I can Select all the values from that database fine but I am rather stuck as how to put the values into the individual labels? Here is the code I have connecting to my database.

  Dim cmd As New SqlCommand
            Dim myConnection As New SqlConnection("Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Alerts.mdf;User Instance=true")

            cmd.Connection = myConnection
            cmd.CommandText = "SELECT DateTime, Description FROM EmailTemplateLoad"


        Catch ex As Exception

        End Try

How can I put the DateTime value into Label1 and the Decription into Label2??

I have had a nose about but can't seem to find the information I need.

Any pointers greatly appreciated.

Accessing gridview cell values


Hi All,

In my application Iam using GridView, in this there are fields (Quantity, Price, Amount) the user can enter Quantity Field value which is a template field (textbox). Iam calculating Amount(Quantity * Price) using Javascript and assigning to the Amount Column cells as below

Gridviewcell.innerText=Quanity * price.

and when user clicks on the Save button I want to add these details of Gridview to the database.

when I try to access the values of the gridview using below code

For i=0 to GridView.rows.count-1

GridView.Rows(i).Cells(2).toString ( for Example)

Next i

It is not displaying the changed value instead it is displaying the default value before calculating the amount.

Before implementing the Javascript part, I had done this in the code behind and it was working fine... Now I just dont want the page to get load so I used javascript.

Can any one help me out in able to access the value of Gridview cells which are assigned using Javascript.



dropdown list wont populate values from database


Hello everyone i need help. Ive been having this problem for almost  3 days now. dropdown list won't populate from database

Below is the code i am using:

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PhotoAlbum.aspx.vb" Inherits="PhotoAlbum" %>

<asp:SqlDataSource ID="categoriesDataSource" runat="server"  
<%$ ConnectionStrings:ConnectionString %>"  
    SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]"> 
<asp:QueryStringParameter Name="UserId" QueryStringField="ID"/> 

load new page and populate the values without database



I'm creating a website of 5 pages using c# (asp.net).

How do i link 2 pages, ie., on click of a button on first page should take me to second page.

Advance thanks,


Datalist not displaying image from database


My database table contains the image file path which will be stored from a
file upload control.The image path in the table will be like "C:\Projects\projectname\projectfolder\Files\1_129308367798080000_images1.jpg"

I am trying to display that image through a datalist control as follows
<asp:DataList ID="cobrandlogolist" runat="server">
                <asp:Image id="CobrandLogo" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "CobrandLogo") %>' Height="100px" Width="100px"


and i am retrieving the image names from the db and assigning as datasource of this datalist in the load event as follows

    DataTable dt = new DataTable();

Accessing a .mdb database in 64 Bit Platform


I want to upgrade the 32bit application to 64 bit application.
In my 32 bit application i use Microsoft Access as the backend database ( simple only with some few tables, no relations)

I have used MFC database classes like CDaoDatabase, CDaoRecordset for accessing the database.
During the upgrading process i came to found that CDaoDatabase classes are now no longer supported in Win64 platforms.
I get the following error:
 fatal error C1189: #error :  DAO Database classes are not supported for Win64 platforms

Also going through some of msdn Q/A articles, i found that CDaoDatabase classes have been deprecated now, or sth like there is no provision for accessing the .mdb in X64 platform.

Is there really no method for accessing the Access database in X64 platform.
Are there any other solutions.....
Is switching to ADO.Net will be the solution....

Hope Somebody will put the light on this topic..

Anur RS..
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend