Can anyone help me to solve this problem that I am facing with GridView in asp.net 3.5 ?
Following is the code: .aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="displaytabledata.aspx.cs" Inherits="diplaydata.displaytabledata" %>
and .aspx.cs code:
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 Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
// Application Import(s)
using images.Utilities;
namespace diplaydata
{
public partial class displaytabledata : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
private DataTable getTable()
{
OracleDataAdapter adap = new OracleDataAdapter("select t.id, t.author, t.description from smstestblob t", "Data Source=ds1;User ID=test;Password=test;");
DataTable dt = new DataTable();
adap.Fill(dt);
adap.Dispose();
return dt;
}
protected void bind()
{
DataTable dr = getTable();
gv_displaydata.DataSource = dr;
gv_displaydata.DataBind();
}
protected void gv_displaydata_PageIndexChanged(object sender, EventArgs e)
{
gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
bind();
}
protected void gv_displaydata_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
bind();
}
protected void gv_displaydata_SelectedIndexChanged(object sender, EventArgs e)
{
gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
bind();
}
protected void gv_displaydata_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
bind();
}
}
}
No data is getting displayed in the GridView on both pages 1 and 2. And when I click on 2 page link, and then first page, 2nd page link is no longer clickable. And one more problem is that though there is data in the table, it is not getting displayed in the GridView.
I am using Oracle 9i. And following is the table creation script:
SQL> CREATE TABLE SMSTestBlob
2 (
3 id number,
4 photo BLOB,
5 author varchar2(100),
6 description varchar2(500)
7 );
Table created.
SQL> alter table SMSTESTBLOB
2 add constraint PK_SMSTESTBLOB_ID primary key (ID);
Table altered.
SQL> create sequence smstestblobid_seq
2 minvalue 1
3 maxvalue 999999999999
4 start with 1
5 increment by 1
6 cache 20
7 cycle
8 order;
Sequence created.
*************************************************
If anyone can help on this, please do so on an urgent basis.
Thanks,
Regards,
Moksha
Kirtan PatelPosted Dec 9, 2009, 5:51 PM
you should Set DataField propery of DataGridView Column to Show the Data like below sample code.
if my answer helps you then check "Do you like this answer" check box please :)
See the highlighted Areas in Above code .
you have not Set the DataField Property of Columns in GridView
MokshasriPosted Dec 9, 2009, 6:14 PM
And can you advise me on the other problems mentioned in the earlier post? 1) Once clicked on page 2, it goes but then it gets disabled (not able to click again and not able to move to page 1) Clicking on page is not responding and it is remaining in page 2 only.
2) In the place of ID, I have tried to replace Image (.gif, .jpg, .bmp etc.,) but it is showing this column: System.Byte[] as the output.
I have tried adding a new column of type Imagefield and tried, but now this field shows "Image" and not image itself.
Thanks in advance for your help again.
Regards,
Moksha
MokshasriPosted Dec 9, 2009, 6:12 PM
And can you advise me on the other problems mentioned in the earlier post? 1) Once clicked on page 2, it goes but then it gets disabled (not able to click again).
2) In the place of ID, I have tried to replace Image (.gif, .jpg, .bmp etc.,) but it is showing this column: System.Byte[] as the output.
Thanks in advance for your help again.
Regards,
Moksha
MokshasriPosted Dec 9, 2009, 5:40 PM
Rows In Data Table 18
This means there is no problem with the data retrieval. As I said in my previous post, paging is displaying 2 pages, but data is not showing.
Can you please advise how to make this returned data displayed in the Gridview and also, how to display image in the place ID column?
Thanks in advance.
Regards,
Moksha
Kirtan PatelPosted Dec 9, 2009, 5:01 PM
After Filling the DataTable in getTable Method
Just check weather you are getting rows in DataTable or not ? by following code
Response.Write("Rows In Data Table "+dt.Rows.Count.ToString());
if it write 0 then check your query :).
check "Do you like this answer" check box if my answer helps you :)