Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleteing a Record and Passing a Record

Status
Not open for further replies.

Caden

Programmer
Dec 9, 2001
101
0
0
CA
Hey Tek-Tips, two questions for you...

So, i've got an Access database driven online application.
Pretty normal pretty simple stuff. I've got a delete function working just fine, but I find that when I make a record...let's say the Primary ID key is 7...if I delete that record then create a new record the next record's ID is going to be 8. I figure this is bad since evetually, although improbable the database even only with one record in it, could be at ID 10000000000 or whatever. Should I be concerned?

Also. I'm trying to create a link, that when clicked on goes to a "details" page for instance. Just like on monster.com when you click on the job it sends you too a bigger page with more details and information on it. How can I pass one record to a page and load only that one record?

I hope I made sense
Thanks
Caden
 
Caden: this ought to be straight forward enough to work out. Your ID problem is that you are using a background AutoNumber for the Key Field, replace it with a straight Long and control it (get a count of the records when you compile the dataset, using, as "1" example):

Code:
...
connPI.Open() 
dgSites.DataSource = cmdSelect.ExecuteReader()
dgSites.DataBind()  
ViewState("myCt") = dgSites.Items.Count.ToString()      
cnnPI.Close()
...

In this case I'm grabbing the number of records bound to the Datagrid. You can put the number in a label and show it, etc. In this way I know the next or last number. Of course there are several ways you might approach this problem.

When passing data to another page the best way is to pass the data through a QueryString, e.g.,

Code:
...
Response.Redirect("mypage.aspx?Ct=" & ViewState("myCt") & "&Name=" & txtName.Text & "&Color=red")
...

You can also use Session or Cache, the latter probably preferred over Session which is server intensive and less scalable (not to mention inadvertent losss of info).

It depends Caden on where the 'clicking' takes place. Inside a Datagrid? What are you using?
 
I figure i'll make the click inside the datagrid, just put it beside everything else.

Thanks for the answer to the first question, i'll give that a try.
 
Caden: Look at the FAQs, there is one in which you pass variables in a DataGrid, just what you need!
 
Looking at the FAQ, i'm not 100% sure that's what I need, maybe i'm being unclear.

Alright, so there are 4 records. The user clicks "details" on record 1. Now I know they are interested in learning more about record 1.

So with that information I want to have a page that displays all of the information on record 1 from the database. So, there's little reason to pass information from the inital page, other then record ID number, because I can just call all that other information again.

I guess what i'm asking, is how do I use the information of knowing what record they want to learn more about, to call only that individual record on a different page.

Caden
 
Caden: You don't want to call the other information again as it requires a 35K opening of a database, though connection pooling may save you most of this, its not a guarantee. General rule on the web - don't hit a database twice if once is enough.

Grab all your variables inside the DataGrid, pass them to the requisite page in a Querystring. One of the examples at the FAQ shows you how to extract the column values from the Grid and pass them on to the next page.
 
Alright, that's a good point that I didn't think about.

I'll work on it, and see how I do.

Thanks for the help Isadore.
 
Anytime Caden, post back if you run into any problems.
 
Alright, so i'm lookin at this...

<asp:TemplateColumn HeaderText="Select Site">
<ItemTemplate>
<asp:HyperLink
id=HyperLink1
runat="server"
Text='<%# DataBinder.Eval(Container,DataItem.AWWCode")%>'
NavigateUrl='<%# "ChemOT.aspx?AwwCode=" & DataBinder.Eval(Container, "DataItem.AWWCode")& "&GroupName=" & DataBinder.Eval(Container, "DataItem.Group_Name")%>'
/>
</ItemTemplate>
</asp:TemplateColumn>


Which looks like C# to me. If i'm correct that it is C# I know this, because I don't know C# and therefore, have basically no idea what i'm lookin at =0p

Any chance you have that hiding in VB.NET for me to look at?

Caden

 
No, its just basic Grid code -- I program in VB so no worries there -- just keep truckin along you're doing great -- I'll be in the background if you need assistance.

Look at this problem as a basic problem in DataGrids, fundamental in that you are picking up grid column data and passing it on to the next page...
 
Alright, I think it's coming together in my brain, let me talk outloud so I can know if i'm going right...

so here we go...
-----This here is my datagrid code---
<asp:DataGrid id="entries" runat="server" AutoGenerateColumns="False" OnPageIndexChanged="entries_Page" Width="602px" Height="158px"
---i'm going to add this Text= to it---
Text='<%# DataBinder.Eval(Container,DataItem.AWWCode")%>'
---The DataBinder.Eval is fine, I assume I need to name the container, a variable or something? The DataItem is the record I want to pass? So that would be my record ID? And I have no idea what the AWWCode is for---


---this here is for sending it to the URL that I want, so---Details is the page i'm sending it too, again AWWcode I have no idea about, fill out the rest of the stuff (container, Dataitem as previous?---
NavigateUrl='<%# "details.aspx?AwwCode=" & DataBinder.Eval(Container, "DataItem.AWWCode")& "&GroupName=" & DataBinder.Eval(Container, "DataItem.Group_Name")%>'/>

I'm still confused, but I think it's coming...slowly

 
errr, i'm adding that to the hyperlink part of the Datagrid code, not the datagrid line...to be clear...
 
Ok. Good Start. Keep in mind that "AWWCode" is the name of the field in the table, so your field name will be entirely different, whatever the column represents.

Ok - the following:

'<%# DataBinder.Eval(Container,DataItem.AWWCode")%>'

represent nothing more than the 'value' or 'text' of the item selected in the Grid. Lets say the item in the table that you want the hyperlink to appear is your ID field or something like that (here the first column up), so yours might read:

'<%# DataBinder.Eval(Container,DataItem.ID")%>'

And of course in the Header of the Grid you can put something else. Let me give you an example of this in action:

Go to:
Here you'll see the first column is you hyperlink column. The grid you'll be looking at uses the code we are discussing. Note when you click on a hyperlink that on the next page the previous DataGrid's values are in the QueryString. This will help.

To send details on the page just do this:

.... & "&Name=" & txtName.Text & "&color=" & lblColor.Text ...

and so on. Hang in there, once you've got it it's as easy as 1-2-3.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top