473,386 Members | 1,973 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,386 software developers and data experts.

There is no row at ...

I have this code so far:

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
Panel2.Visible = false;
Panel1.Visible = true;
Label1.Text = "Logged in as: " + Session["VisitorsName"];
sqlConnection1.Open();
sqlFilesIDAdapter.SelectCommand.Parameters["@ID"].Value =
Session["VisitorsID"];
sqlFilesIDAdapter.Fill(filesIDData1,"Files");
DataGrid1.DataBind();
}
}

private void DataGrid1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
Label2.Text =
filesIDData1.Tables["Files"].Rows[DataGrid1.SelectedItem.ItemIndex]["TP_
Name"].ToString();
}
Now when I click on a row I get: 'There is no row at ' and then the
number. If I remove the !IsPostBack condition it works. Why is this?

--
Kind regards,

Stijn Verrept.
Nov 18 '05 #1
6 989
Because the data is loaded the first time into the grid, but the second time
you haven't loaded the data therefore the grid is empty when you change the
index. You could store the object in the Viewstate and then recover it on
further loads, though this can make for a rather large page as the Viewstate
data tends to bloat a page pretty well.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Stijn Verrept" <stijn@no_s.p.a.n.entrysoft.com> wrote in message
news:40*********************@news.skynet.be...
I have this code so far:

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
Panel2.Visible = false;
Panel1.Visible = true;
Label1.Text = "Logged in as: " + Session["VisitorsName"];
sqlConnection1.Open();
sqlFilesIDAdapter.SelectCommand.Parameters["@ID"].Value =
Session["VisitorsID"];
sqlFilesIDAdapter.Fill(filesIDData1,"Files");
DataGrid1.DataBind();
}
}

private void DataGrid1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
Label2.Text =
filesIDData1.Tables["Files"].Rows[DataGrid1.SelectedItem.ItemIndex]["TP_
Name"].ToString();
}
Now when I click on a row I get: 'There is no row at ' and then the
number. If I remove the !IsPostBack condition it works. Why is this?

--
Kind regards,

Stijn Verrept.

Nov 18 '05 #2
Mark Fitzpatrick wrote:
Because the data is loaded the first time into the grid, but the
second time you haven't loaded the data therefore the grid is empty
when you change the index. You could store the object in the
Viewstate and then recover it on further loads, though this can make
for a rather large page as the Viewstate data tends to bloat a page
pretty well.


Thanks Mark for your answer, I understand now. But what I don't get is
why I need to reload the data if all I do is show a field in a label?
Is it possible to do this client side?

--
Kind regards,

Stijn Verrept.
Nov 18 '05 #3
I agree, I don't know that I would recommend the viewstate because it can get pretty large, depending on how much data you're talking about

One of the things I've done is if the page is not a postback then load the grid. On the SelectedIndexChanged event on the grid I do all the manipulation and whatever I need to do, then I do a response.redirect to that same page I'm already on. This works pretty well (I think) if you're programmatically doing something with the data and leaving the user out of any data manipulation. However, if you need the user to manipulate the data this won't work so well (I don't think)

HTH
Jeremy
Nov 18 '05 #4
Stijn

The reason you need to reload the data is because when a postback happens you loose all of data. I know it seems bizarre, but that's how the web works. Every HTTP request to a file (or page) acts like a brand new request, that's why in your pages you'll need to put in the appropriate checks to ensure the page is a PostBack or not

I'm not sure about working with the grid on the client though. But I hope this answers your question about why you need to reload the data

Jeremy
Nov 18 '05 #5
Stijn Verrept wrote:
Mark Fitzpatrick wrote:

Because the data is loaded the first time into the grid, but the
second time you haven't loaded the data therefore the grid is empty
when you change the index. You could store the object in the
Viewstate and then recover it on further loads, though this can make
for a rather large page as the Viewstate data tends to bloat a page
pretty well.

Thanks Mark for your answer, I understand now. But what I don't get is
why I need to reload the data if all I do is show a field in a label?
Is it possible to do this client side?


If you are looking up a value in the same table you bound to, just
create some invisible/hidden columns with the other column values you
need later on.

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #6
Craig Deelsnyder wrote:
If you are looking up a value in the same table you bound to, just
create some invisible/hidden columns with the other column values you
need later on.


Aha! Thanks :)

I changed it to Label2.Text = DataGrid1.SelectedItem.Cells[1].Text; and
this works great. I also replaced the Dataset by a DataReader which
seems to speed it up some more :)

--
Kind regards,

Stijn Verrept.
Nov 18 '05 #7

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

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
2
by: Sreedharan | last post by:
Hi, I am using C#. Is there no Join method (in thread class)for Smart device application? And Also i noticed that Name property isn't there(got compiler error when trying to use them) Is this...
43
by: Rob R. Ainscough | last post by:
I realize I'm learning web development and there is a STEEP learning curve, but so far I've had to learn: HTML XML JavaScript ASP.NET using VB.NET ..NET Framework ADO.NET SSL
4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
210
by: Christoph Zwerschke | last post by:
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an "ordered dictionary" class at least in the standard list? Time and again...
44
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a...
5
by: B1ackwater | last post by:
We've fooled around with Access a bit, but only using the single-user store-bought version. It seems to be a good database - versatile and infinitely programmable - and can apparently be used as a...
28
by: H J van Rooyen | last post by:
Hi, I want to write a small system that is transaction based. I want to split the GUI front end data entry away from the file handling and record keeping. Now it seems almost trivially easy...
13
by: andrewanderson | last post by:
hi all, i'm wondering is there any other alternative to do a timestamp which consists of date and time!! below is a program i've created but its too long and to large i would like to know other...
6
by: Richard Maher | last post by:
Hi, Now that I am aware that JS on a page in Frame A can directly call a function on a page in Frame B, I no longer have to continue with my frameB.location.reload() fudge in order to get some...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.