473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Hyperlinks on a DataGrid

Hello,

I'm trying to get the details out of a datagrid component and it works fine
when I'm accessing the first page of the datagrid, but when I try to click
on the details hyperlink for an item that is not on the first page, the
web-page displays the first page of the datagrid again and show the details
of the field on the same location, but on the first page.

For instance, if I have the first page with the following data:

Header:
DATE NAME MSG HYPERLINK

data
01/05 A B Details
02/05 C D Details

And on the second page I've got something like this:

Header:
DATE NAME MSG HYPERLINK

data
01/05 E F Details
02/05 G H Details

If I click on the details for E and F (first line of the second page), the
page returns to the first one and the details return as NAME=A and MSG=B.

Here is my Page_Load event, I tried to use the FillData only when the server
starts, but then when I have a postback the datagrid is empty.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";

oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}
}

Here is my PageIndexChanged event:

private void DataGrid1_PageIndexChanged(
object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}

And here is my ItemCommand event:

private void DataGrid1_ItemCommand(
object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName=="det")
{
Label5.Text = "Correct Command";

Label3.Text = e.Item.Cells[0].Text;
Label4.Text = e.Item.Cells[1].Text;
Label6.Text = e.Item.Cells[2].Text;
}
}

Please, if you have any idea, let me know.

Thanks.
Ruy.
Nov 17 '05 #1
3 1639
Ruy, It looks to me like your page load event, which always runs, rebinds
the datagrid to the dataset and you will be setting on page one. Then your
Item Event runs but of course you are looking at the wrong page now. So,
only bind (and rebind) the dataset when you need to. In your case, bind the
data set the first time (!page.ispostback) and pageIndexChanged. Note, you
still need to load the dataset each time or add a load of the dataset in the
pageIndexChanged event.

....Chuck

"Ruy Castelli" <an****@newsgroup.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
Hello,

I'm trying to get the details out of a datagrid component and it works
fine when I'm accessing the first page of the datagrid, but when I try to
click on the details hyperlink for an item that is not on the first page,
the web-page displays the first page of the datagrid again and show the
details of the field on the same location, but on the first page.

For instance, if I have the first page with the following data:

Header:
DATE NAME MSG HYPERLINK

data
01/05 A B Details
02/05 C D Details

And on the second page I've got something like this:

Header:
DATE NAME MSG HYPERLINK

data
01/05 E F Details
02/05 G H Details

If I click on the details for E and F (first line of the second page), the
page returns to the first one and the details return as NAME=A and MSG=B.

Here is my Page_Load event, I tried to use the FillData only when the
server starts, but then when I have a postback the datagrid is empty.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";

oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}
}

Here is my PageIndexChanged event:

private void DataGrid1_PageIndexChanged(
object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}

And here is my ItemCommand event:

private void DataGrid1_ItemCommand(
object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName=="det")
{
Label5.Text = "Correct Command";

Label3.Text = e.Item.Cells[0].Text;
Label4.Text = e.Item.Cells[1].Text;
Label6.Text = e.Item.Cells[2].Text;
}
}

Please, if you have any idea, let me know.

Thanks.
Ruy.

Nov 17 '05 #2
Hi Chuck, thanks for answering.

I changed the events as you said, but now the datagrid just disappears when
I click on the page number or Next/Previous.

Here are the new events:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!PostBack)
{
try
{
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";

oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}
}
}

Here is my PageIndexChanged event:

private void DataGrid1_PageIndexChanged(
object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;

try
{
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";

oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}

DataGrid1.DataBind();
}

Thanks.
Ruy.

"Chuck Rudolph" <ch**********@newsgroup.nospam> escreveu na mensagem
news:uB***************@TK2MSFTNGP12.phx.gbl...
Ruy, It looks to me like your page load event, which always runs, rebinds
the datagrid to the dataset and you will be setting on page one. Then your
Item Event runs but of course you are looking at the wrong page now. So,
only bind (and rebind) the dataset when you need to. In your case, bind
the data set the first time (!page.ispostback) and pageIndexChanged. Note,
you still need to load the dataset each time or add a load of the dataset
in the pageIndexChanged event.

...Chuck

"Ruy Castelli" <an****@newsgroup.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
Hello,

I'm trying to get the details out of a datagrid component and it works
fine when I'm accessing the first page of the datagrid, but when I try to
click on the details hyperlink for an item that is not on the first page,
the web-page displays the first page of the datagrid again and show the
details of the field on the same location, but on the first page.

For instance, if I have the first page with the following data:

Header:
DATE NAME MSG HYPERLINK

data
01/05 A B Details
02/05 C D Details

And on the second page I've got something like this:

Header:
DATE NAME MSG HYPERLINK

data
01/05 E F Details
02/05 G H Details

If I click on the details for E and F (first line of the second page),
the page returns to the first one and the details return as NAME=A and
MSG=B.

Here is my Page_Load event, I tried to use the FillData only when the
server starts, but then when I have a postback the datagrid is empty.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";

oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}
}

Here is my PageIndexChanged event:

private void DataGrid1_PageIndexChanged(
object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}

And here is my ItemCommand event:

private void DataGrid1_ItemCommand(
object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName=="det")
{
Label5.Text = "Correct Command";

Label3.Text = e.Item.Cells[0].Text;
Label4.Text = e.Item.Cells[1].Text;
Label6.Text = e.Item.Cells[2].Text;
}
}

Please, if you have any idea, let me know.

Thanks.
Ruy.


Nov 17 '05 #3
Hello Chuck,

I followed your tips, but it still didn't work. Then I was checking some
configuration and I noticed that somehow the document properties
"enableSessionState" and "enableViewState" were set to false. When I set
then to true, everything worked.

Thanks.
Ruy.

"Chuck Rudolph" <ch**********@newsgroup.nospam> escreveu na mensagem
news:uB***************@TK2MSFTNGP12.phx.gbl...
Ruy, It looks to me like your page load event, which always runs, rebinds
the datagrid to the dataset and you will be setting on page one. Then your
Item Event runs but of course you are looking at the wrong page now. So,
only bind (and rebind) the dataset when you need to. In your case, bind
the data set the first time (!page.ispostback) and pageIndexChanged. Note,
you still need to load the dataset each time or add a load of the dataset
in the pageIndexChanged event.

...Chuck

"Ruy Castelli" <an****@newsgroup.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
Hello,

I'm trying to get the details out of a datagrid component and it works
fine when I'm accessing the first page of the datagrid, but when I try to
click on the details hyperlink for an item that is not on the first page,
the web-page displays the first page of the datagrid again and show the
details of the field on the same location, but on the first page.

For instance, if I have the first page with the following data:

Header:
DATE NAME MSG HYPERLINK

data
01/05 A B Details
02/05 C D Details

And on the second page I've got something like this:

Header:
DATE NAME MSG HYPERLINK

data
01/05 E F Details
02/05 G H Details

If I click on the details for E and F (first line of the second page),
the page returns to the first one and the details return as NAME=A and
MSG=B.

Here is my Page_Load event, I tried to use the FillData only when the
server starts, but then when I have a postback the datagrid is empty.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";

oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}
}

Here is my PageIndexChanged event:

private void DataGrid1_PageIndexChanged(
object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}

And here is my ItemCommand event:

private void DataGrid1_ItemCommand(
object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName=="det")
{
Label5.Text = "Correct Command";

Label3.Text = e.Item.Cells[0].Text;
Label4.Text = e.Item.Cells[1].Text;
Label6.Text = e.Item.Cells[2].Text;
}
}

Please, if you have any idea, let me know.

Thanks.
Ruy.


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
Hi all, My app contains a datagrid with hyperlinks inside and these hyperlinks all point back to the same page. The problem is that I have a 'search' user control and the viewstate changes once...
2
by: Alex | last post by:
I'm reposting my issue with some more info. I would like to use a DataGrid to display my DataSet. My DataSet is from a table in a SQL DB. Both columns in the table are strings. I would like...
6
by: Trint Smith | last post by:
Can a datagrid have thumbnails and hyperlinks? Does anyone have a good sample of that? And is a datagrid better than results pages on searches of a sql server database? Thanks, Trint .Net...
1
by: Jason L James | last post by:
Hi all, I have datagrid with a column that is to contain hyperlinks to other documents. The is in the columns from a bound data source but I would like to format them as hyperlinks so that I...
2
by: Bishoy George | last post by:
I have a database table with many columns: ItemID , ItemName , ItemLink , ItemSize I want to display items through a datagrid or whatever in the way that the ItemName is written and has the...
1
by: rcoco | last post by:
Hi all, I have two datagrid, one has a list of allowed user of the second datagrid. The second datagrid is an inserting datagrid and it Function properly. Now where my problem is I need to be able...
1
by: rcoco | last post by:
Hi all, I have this big problem with hyperlinks I would appriciate any help please. My web site has two datagrids on the same page. And one has a list of names of the users which are in form of...
2
by: =?Utf-8?B?S3VtYXIuQS5QLlA=?= | last post by:
HI I want to disable the underline of a hyperlink text in a hyperlink column of datagrid/gridview in the content page. If I am writing a css class to disable it in the master page then its...
2
by: Jonathan | last post by:
In the sample code below, how do I make the various text items in a datagrid column have a clickable hyperlinks? e.g. Ford Mustang should be a link to www.mysite.com/mustang.htm </head>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.