Gridview linking to formview but NOT using formview.pageindex = gridview.selectedindex

I would like to be able to open my Formview based on my selection in Gridview.

I don't want to use formview.pageindex = gridview.selectedindex (ie using selectedIndexchanged) because if a row is deleted in my source table (both Gridview and Formview have the same datasource)  then my selected index will not match up properly to my formview.pageindex.

So what I want to do is open Formview based on the primary key of the table. - ie when I click the GridView, the formview is then opened based on the key of the value in the GridView selection.

Can anyone point me in the right direction on this one?

Is it something like

MyFormView.Page.Items.Item(1) = MyGridView.SelectedDataKey(1)

11/23/2006 12:05:04 AM 72751 articles. 3 followers. Follow

7 Replies

Similar Articles

[PageSpeed] 54

hi mate,

here's what i did, i used control like sqldatasource to bind formview & gridview at begining.  following is selectedindexchanging event of gridview. datakeynames = "pid" for both controls, pid is my primary key.

protected void gv_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)


DataView dv = (DataView)this.SqlDataSource1.Select(DataSourceSelectArguments.Empty); //this is very crucial, getting dataview of sqldatasource.

dv.RowFilter =

"Pid="+ GridView1.DataKeys[e.NewSelectedIndex].Value;

FormView1.DataSourceID =

""; // was getting error without it as datasource = dv & datasourceid referring to contol id which in my case was sqldatasource1 so blanked it.

FormView1.DataSource = dv;



hope it helps.



Kind Attn: If a reply to your post helped you, kindly mark it as Answered.
Please save Animals Help World Society For Protection Of Animals,
Protect these speechless creatures of GOD
11/27/2006 5:20:36 PM


 I'm trying to convert to VB.NET.

I've converted to the following: 

Protected Sub PCDetailsGridView_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs) Handles PCDetailsGridView.SelectedIndexChanging

Dim Pid As Integer = PCDetailsGridView.DataKeys(e.NewSelectedIndex).Value

Dim dv As DataView = CType(Me.sqlPCDetails.Select(DataSourceSelectArguments.Empty), DataView)

dv.RowFilter = Pid

frmPCDetails.DataSourceID = ""

frmPCDetails.DataSource = dv


End Sub


I get the following error:

An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

I get the error on this line:

Dim Pid As Integer = PCDetailsGridView.DataKeys(e.NewSelectedIndex).Value

11/29/2006 7:29:33 AM

hi Benjamin

this line is error in your code

dv.RowFilter = Pid

it should be

dv.RowFilter = "Pid = " + pid. i'm assuming here pid is actually a column in your table you could replace it

dv.RowFilter = "some column = " + value.

i hope you getting what i mean.



Kind Attn: If a reply to your post helped you, kindly mark it as Answered.
Please save Animals Help World Society For Protection Of Animals,
Protect these speechless creatures of GOD
11/29/2006 7:39:31 AM

I didn't have any luck with this code for some reason.

I have found the best way to do what I'm doing is to give the formview a different SqlDatasource and passing in a session variable into the formview's query as a filter.

ie.  Session.Item("EmployeeNumberSession") = UserDetailsGridview.SelectedRow.Cells.Item(13).Text

into the filter to give my my unique (and definately existing) record with error handling if the database record does not exist via try catch.

12/1/2006 1:02:56 AM

hi Benjamin,

sorry mate but its working alright here

Protected Sub gv_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
 Dim dv As DataView = CType(Me.SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
 dv.RowFilter = "Pid=" + GridView1.DataKeys(e.NewSelectedIndex).Value
 FormView1.DataSourceID = ""
 FormView1.DataSource = dv
End Sub

you could replace underlined line with this

dv.RowFilter = "EmployeeNumber =" + GridView1.SelecteRow.Cells.Items(13).Text, & then try the code i sent. if employeenumber is varchar field then try this

dv.RowFilter = "EmployeeNumber = '" + GridView1.SelecteRow.Cells.Items(13).Text + "'"

hope it helps now.



Kind Attn: If a reply to your post helped you, kindly mark it as Answered.
Please save Animals Help World Society For Protection Of Animals,
Protect these speechless creatures of GOD
12/1/2006 1:57:43 AM

Hi Satish,

 After Implementing your code i'm getting following exception.

The FormView 'counrtyFormView' fired event ModeChanging which wasn't handled.

Please Let me Know What's wrong there is.


Muhammad Siddique

Software Engineer / Analyst

11/14/2008 7:07:53 AM

u can also get the datakey value by  PCDetailsGridView.SelectedDataKey.Value did u tried these?

11/14/2008 9:57:33 AM

Similar Artilces:

Gridview, Gridview, Formview
 Something is vexing me. I have a page with 2 gridviews and a formview.Gridview "A" is a simple gridview, gridview "B" is populated off of a SelectedIndexChanged event of Gridview "A". Easy enough, they work like champs!I am now trying to get it so that when you the SelectedIndexChanged event fires from Gridview "B", the formview pops up all pretty like. What I get is a big bowl o' nothing. There is nothing in the data screaming out as an issue. <script runat="Server"> Protected Sub Page_Load(ByVal sender As...

(master/detail) control using gridview and formview controls problem...
hi guys, i'm new to .net programming and have been toying with the (master/detail) control using gridview and formview controls...however, i can't seem to drilldown to the correct record when the primary key is a composite key. please help....   <asp:GridView ID="GridView1" runat="server" DataKeyNames="ServiceID,VersionNum" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"               &nbs...

Linking Gridview and Formview Controls
hi guys,   i have sort of a genaeral question about using a gridview as a selector panel and populating my formview control with data after a user selects an item from the gridview. Well i guess that is the question above :)  Basically I have a datasource on the page that populates both the gridview and the formview and when a user clicks on the gridview (selects) I would like to move to the correct page on the formview.  I would like to avoid calling the DB again and using SQL statements if I can.  I know the code should go in the gridview.SelectedIndexChanged event I...

Looking for a beginners tutorial or guide on using GRIDVIEW control with FORMVIEW control
what i want to be able to do is add a gridview control onto the page.. have it display my results then have a link to take me to another page where they can edit the data if needed I have a current project im working on that i have a search function on the top part and that value us passed into the GRIDVIEW below it and displays records.. each of those records has a link to a edit page.. since the gridview is merely a small teaser of all the data for the records.. the next page will display ALL fields for that record within a FORMVIEW.. The itemtemplate displays all the data in a nice fo...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

How to: 2.0 Encrypting Field Data Using a Formview Control and a Gridview control for SQL
The Exercise: Using a Formview Control and a Gridview control to Encrypt data going into SQL, Decrypt it for display, and Be able to Edit it. Using Visual Studio 2005 ASP.NET 2.0 Framework   Files needed: – QSEnc64.vb to be placed in the App_Code folder of your application TestInsertEdit.aspx in the root of the application TestInsertEdit.aspx.vb in the root of the application A Web Config file with a valid ConnectionString Your_SQLConnectionString A SQL Database that you can add the test table to (see script below)   Hopefully this exercise will save you the time it to...

Using MultiView for a GridView and a FormView Control
I have three tables where the Identifying key is CLientID - one table has CLientID as Primary and two tables are foreign.  I have set up a RadioButtonList1 to select a client from the Client Table.  I have a RadioButtonList2 that a user can select either Cars (RadioButton1) or Investments (RadioButton2).  When a user selects a CLient and then selects Cars, View1 of the Multiview will display the cars from the cars table for that Client.  When Investments is selected, View2 displays the investments for that client from the investment table.  Let's say a ...

Problem regarding GridView within a FormView which is linked to a separate GridView.
Ok, my first post! I've ran across a problem regarding GridViews and FormViews. I'm using ASP.NET 2.0 (C#). What I've got at the moment is a GridView which returns high-level information. I've then got a FormView which is linked to this GridView through a FilterParameter, so that when the User selects a different item in the GridView, the form is refreshed and the new more detailed information is displayed in the FormView. However, I have a load of child records hanging off the record in the GridView, and I need to display them. I've tried going down the route of putting another GridView...

Linking Gridview and Formview using primay key
Hi Friends, I am using a sortable Gridview and a formview and a SQLdatasource. I am using the below code to link the two views, so when the user select a row in the Gridview details of that record will be shown in the Formview without any problem. The problem arises only when i sort the Gridview, since the order will change while you sort the column.row = GridView1.SelectedRow.RowIndex()orderno = GridView1.Rows(row).Cells(1).Text().ToString() FormView1.PageIndex = orderno - 1 To solve this problem. I want to get the primary value of the select row in gridview and pass that to t...

Multiview, gridview, formview. How to access a formview control's properties?
I have a multiview with three views. The first view is a GridView where the user can select a row. When selecting a row, the second view is shown. This view contains a FormView control with the EditItemTemplate enabled. By clicking a linkbutton located nearby one of the fields the third view appears. This is also a Gridview where the user can select one row. When selecting a row, the second view is shown.And here is the case; how can i access and change the text to the control in the formview that is affected by which row the user clicks in the third view?GridView2.SelectedRow.Cells[0].Text ...

gridView formview when formview has no data
I have a formview/gridview pair and the SELECT statement that I am using for the formview sqldatasource can return a count = 0. When this happens, the formview shows nothing (a blank spot) -- although a property lets you state to the user there is no data. I would like to give the user the option to add a new record. I have tried to set the Formview mode to INSERT when the count = 0, but this will always show the blank formview insert page. I'd rather give the use an option to show the insert page. My attempt was to add a button that becomes visible only when the count = 0. Then, I set...

Customising Edit mode inside of GridView
I'm a little embarrassed by my previous post relating to this topic (1615751.aspx).  I was incorrect about my EditItemTemplate changes being ignored - I hadn't even enabled them.  I realized as I was staring at the source yesterday that the declarative "ShowEditButton=True" inside the GridView was the editing control that I was seeing in the browser, and that I needed a separate Edit button (CommandName=Edit) inside FormView to display my EditItemTemplate changes.My new question is: how do I customize the GridView editing controls?  I'd prefer the editing to take place inside ...

Link FormView to GridView
 Hello,I have the following GridView:  Private Sub gvTags_Init(ByVal sender As Object, ByVal e As EventArgs) Handles gvTags.Init    With gvTags      .CssClass = "GridView"      .DataKeyNames = New String() {"TagId"}      .DataSource = ldsTags      .ID = "gvTags"    End With  End Sub ' gvTags_Init How can I link it to a FormView so when I edit or insert a record using the FormView when I click the Edit or Insert butt...

Should I use a FormView and GridView
I'm going to try and build a payment batching page. I will need to enter payents for existing loans as well as start new loans with payments. Has anyone done this type of page? If yes, what controls did you use?Thank youJackxxx I like the FormView for that sort of thing, if for no other reason as a head start, because you get all the individual parts you can customize....

Web resources about - Gridview linking to formview but NOT using formview.pageindex = gridview.selectedindex -

Skip to navigation Skip to content Help using this website - Accessibility statement Send news tips/photos to 0414 284 637 Fairfax Digital Times ...

Skip to navigation Skip to content Help using this website - Accessibility statement Fairfax Digital Times Domain Drive MyCareer RSVP Newsletters ...

World News Australia
Video Full Episodes News & Current Affairs The World Game SBS Food SBS Films Language Sites Aboriginal African Albanian Amharic Arabic Armenian ...

Sydney 20:46
Skip to navigation Skip to content Help using this website - Accessibility statement See today's paper Fairfax Digital SMH Domain Drive MyCareer ...

Skip to navigation Skip to content Help using this website - Accessibility statement Send your news tips/photos to Fairfax ...

World Weather
Weatherzone world weather has the weather forecast, current conditions and climate information for hundreds of international cities and towns ...

Inside Business
Search: Radio TV Shop News Sport Local Children Science Environment more Topics help INSIDE BUSINESS Home Archive Vodcast About Contact Us Latest ...

0)location.href='/section/searchsection.php?sectionid='+this.options[this.selectedIndex].value" name="searchsection" class="tese_zh" style="margin-right:14px; ...

鏈珯鎼滅储 浣滆€?/Option> 鏍囬 鍐呭 绠€浣?/A> 绻佷綋 璁句负棣栭〉 鍔犲叆鏀惰棌 鏀垮姟淇℃伅 鏈烘瀯鑱岃矗 淇℃伅鍏紑 閲嶈淇℃伅 宸ヤ綔淇℃伅 鍖哄幙淇℃伅 娉曞緥娉曡 閫氱煡鍏憡 澶т簨璁?/A> 鍔炰簨澶у巺 涓嬭浇涓績 璇佷欢鍔炵悊 琛屾斂瀹℃壒 ...

中国福利彩票发行管理中心 0)[this.selectedIndex].

Resources last updated: 12/9/2015 7:50:14 PM