list view
Hi frnds plz help me, I am displaying values fro database to listview through code by'listvw.datasource=ds', but i didnt get the values to be displayed in list view,
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Glenn SanchezPosted May 18, 2012, 1:45 AM
Kunal VaishyaPosted May 18, 2012, 1:38 AM
If
Ds is DataSet Then
try this
listvw.datasource=ds.Table[0];
listvw.dataBind();
Glenn SanchezPosted May 18, 2012, 1:36 AM
Satyapriya NayakPosted May 18, 2012, 7:30 AM
For web application below code
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ListView_in_Asp.net._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace ListView_in_Asp.net
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
ListView1.DataMember = "employee";
ListView1.DataSource = ds;
ListView1.DataBind();
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer
Satyapriya NayakPosted May 18, 2012, 4:06 AM
Please mention it is a web or windows application.If it is a windows application then below is the code.
Try this...
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Listview_display
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
string str;
DataSet ds;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listView1.Columns.Add("ID", 70, HorizontalAlignment.Center);
listView1.Columns.Add("GRADE", 70, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.GridLines = true;
listView1.BackColor = Color.Aqua;
listView1.ForeColor = Color.Blue;
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from test Query";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "test Query");
con.Close();
dt = ds.Tables["test Query"];
int i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
listView1.Items.Add(dt.Rows[i].ItemArray[0].ToString());
listView1.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());
}
}
}
}
Thanks
If this post helps you mark it as answer
anil johnPosted May 18, 2012, 1:40 AM
EhteshamPosted May 18, 2012, 1:36 AM
listvw.datasource=ds.tables[0];
listvw.dataBind();