Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 8th, 2007, 06:22 AM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Jumping to specific record in FormView based on ID

This feels like it ought to be really simple, but I can't seem to figure it out. I have a FormView control populated by an SQL Data Source containing any number of records, and I have the value of one of the columns (a unique ID) for the specific record I want to jump to. But I haven't been able to find a .Find method or something similar to get me there.

Still pretty new to FormViews so I'm sure I'm overlooking the obvious, but how do I find out what .PageIndex to jump to to get to the right record?
 
Old January 11th, 2007, 10:58 AM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Can U suggest me how u fixed the issue.I have a similar kind of issue

Pradeep Murti
 
Old January 11th, 2007, 11:03 AM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The Solution may be Database Related Issue .My Requirement is like this .
1.I have one formview in Insert Mode which takes input (Name,Address,Age) Say .In tblStudent table studId is Created (Primary Key) .I want to get the value of RegId in my 2nd form view .In the 2nd formview there will be field like (StudId, Mark1,Mark2,Mark3) .How can I get the value of StudId in 2nd formview. Thanx .............

Pradeep Murti
 
Old January 11th, 2007, 11:10 AM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't have a permanent solution yet. I wasn't able to find a better option so far than to just walk through the formview record by record (databinding each time to make the SelectedValue property update), comparing IDs to see if it is the right record, and incrementing further when it wasn't. Like this:

myFormView.PageIndex = 0;
myFormView.DataBind();

for (int iRowIndex = 0; iRowIndex < myFormView.DataItemCount; iRowIndex++)
{
    if (myFormView.SelectedValue.ToString() != sMyID)
    //formview field holding the ID needs to be set as datakey
    {
        myFormView.PageIndex++;
        myFormView.DataBind();
    }
    else
    {
        //correct record found
        break;
    }
}

It works and with a small number of records it doesn't even take that long (on an SQL Server backend). But I got noticeable overhead starting with a thousand records or so, so I still need to find a better approach eventually. This won't do for production.
 
Old January 26th, 2007, 01:11 PM
Registered User
 
Join Date: Dec 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm also havin roblem similar to this...i want to modify records but to do so i want the user to enter the record id first and then the whole record should be dislayed.
There should be a text box which asks for the record id.When the user enters the record id then the record should be dislayed and then there should be an option to edit the record..hoe u guys got what i wanted.

Please help me on this.

 
Old June 18th, 2007, 04:37 AM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Better late than never, I guess - found a solution that involves only one DataBind rather than having to do it once for every record (which is where the bulk of the overhead came from). For anybody who might still need it:

//string sMyID contains the ID to look for. myFormView contains any number of records.
//Column holding the ID is myIDColumn.

DataRowView myDataRowView = myFormView.DataItem as DataRowView;
bool bFoundRecord = false;

for (int iRowIndex = 0; iRowIndex < myDataRowView.DataView.Count; iRowIndex++)
{
    if (myDataRowView.DataView[iRowIndex].Row["myIDColumn"].ToString() == sMyID)
    {
        //found record
        bFoundRecord = true;
        myFormView.PageIndex = iRowIndex;
        myFormView.DataBind(); //only one DataBind() this time, saves a lot of overhead.
        break;
    }
}

if (!bFoundRec)
{
    //whatever needs to be done when the record is not found
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Return to Inserted Record - FormView rit01 ASP.NET 2.0 Basics 15 January 27th, 2007 12:04 PM
choose specific record ar555 Dreamweaver (all versions) 12 January 12th, 2007 01:04 PM
Going to a specific record in a separate subform discorhino Access VBA 2 August 7th, 2006 12:35 AM
Need to apply to only a specific node based on var rfleming XSLT 1 November 17th, 2004 05:16 PM
Link to a specific record rexecampbell Classic ASP Basics 2 April 7th, 2004 01:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.