473,785 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView / FormView binding question

Bob
Hi All:
I have a GridView with several pages and a FormView linked via a
ControlParamete r. The FormView populates correctly when the user makes
a selection from the first page of the grid. However, when the user
goes to the next page of the grid, the ControlParamete r is passing in a
null (or the default value) to the FormView. I want to populate the
formview with the data from the first item of the grid. I've set
GridView1.Selec tedIndex in GridView1_PageI ndexChanging, but no luck.
Any ideas?

Aug 1 '06 #1
2 4381
I don't know why this is happening with you but try the following ASP.NET 2.0
script on your aspx page, note that I didn't use any code behind and I'm
using SqlDataSource and the same aspect will work for ObjectDataSourc e.

<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
AutoGenerateCol umns="False"
DataKeyNames="P roductID" DataSourceID="S qlDataSource1">
<Columns>
<asp:CommandFie ld ShowSelectButto n="True" />
<asp:BoundFie ld DataField="Prod uctID" HeaderText="Pro ductID"
InsertVisible=" False"
ReadOnly="True" SortExpression= "ProductID" />
<asp:BoundFie ld DataField="Prod uctName"
HeaderText="Pro ductName" SortExpression= "ProductNam e" />
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>"
SelectCommand=" SELECT [ProductID], [ProductName] FROM
[Products]"></asp:SqlDataSour ce>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="P roductID"
DataSourceID="S qlDataSource2">
<EditItemTempla te>
ProductID:
<asp:Label ID="ProductIDLa bel1" runat="server" Text='<%#
Eval("ProductID ") %>'></asp:Label><br />
ProductName:
<asp:TextBox ID="ProductName TextBox" runat="server"
Text='<%# Bind("ProductNa me") %>'>
</asp:TextBox><br />
UnitPrice:
<asp:TextBox ID="UnitPriceTe xtBox" runat="server" Text='<%#
Bind("UnitPrice ") %>'>
</asp:TextBox><br />
UnitsInStock:
<asp:TextBox ID="UnitsInStoc kTextBox" runat="server"
Text='<%# Bind("UnitsInSt ock") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update">
</asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
ProductName:
<asp:TextBox ID="ProductName TextBox" runat="server"
Text='<%# Bind("ProductNa me") %>'>
</asp:TextBox><br />
UnitPrice:
<asp:TextBox ID="UnitPriceTe xtBox" runat="server" Text='<%#
Bind("UnitPrice ") %>'>
</asp:TextBox><br />
UnitsInStock:
<asp:TextBox ID="UnitsInStoc kTextBox" runat="server"
Text='<%# Bind("UnitsInSt ock") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
ProductID:
<asp:Label ID="ProductIDLa bel" runat="server" Text='<%#
Eval("ProductID ") %>'></asp:Label><br />
ProductName:
<asp:Label ID="ProductName Label" runat="server" Text='<%#
Bind("ProductNa me") %>'>
</asp:Label><br />
UnitPrice:
<asp:Label ID="UnitPriceLa bel" runat="server" Text='<%#
Bind("UnitPrice ") %>'></asp:Label><br />
UnitsInStock:
<asp:Label ID="UnitsInStoc kLabel" runat="server" Text='<%#
Bind("UnitsInSt ock") %>'>
</asp:Label><br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>"
SelectCommand=" SELECT [ProductID], [ProductName], [UnitPrice],
[UnitsInStock] FROM [Products] WHERE ([ProductID] = @ProductID)">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Grid View1" Name="ProductID "
PropertyName="S electedValue"
Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>

Hope this will help you
Aug 2 '06 #2
Note the behaviour when you select a record and then move to next page.
suppose that you select record number 2, when you move to next page or any
other page, the record number 2 will on the seeked page will be apear as
selected.
Aug 2 '06 #3

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

Similar topics

5
7832
by: mosscliffe | last post by:
Following Mr Tabors Video on Databinding I implemented the following code In GridViewSelectedIndexChange I coded DetailsView1.pageindex = gridview1.selectedindex This works fine for the first page of the binding, but once thr gridview re-arranges - the formview only ever sees in effect the rowdisplayedindex
1
1483
by: Sean | last post by:
I have them working together just fine and update does make changes only I have one small problem. Changes made on the formview do not reflect on the grid on postback. I have to leave the page and come back before seeing the changes. Now on the binding I use custom binding option for elements on the formvuew instead of the option above it which I am not clear I understand what its for. I dont think explictly binding to the source on...
0
4749
by: ThePurpleCat | last post by:
Hi, I'm a newbie to ASP.NET programming but not to Visual Studio. I'm having trouble getting my Master-Details page to work. I have a page enabled GridView which is linked to a FormView control through an objectdatasource. The paging on my GridView works fine except that when I change the page the FormView does not update. I tried setting the selectedindex to 0 in the GridView's PageIndexChanged event and manually binding the formview...
0
1882
by: hardieca | last post by:
Hi, My formview or gridview control stops updating or deleting a record once the record has a null value. I have table tblTest with the following pkID int NOT NULL **IDENTITY COLUMN** string1 varchar(30) string2 varchar(30)
0
1995
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have few questions and hopefully you can provide me some answers. 1. Best place for DataBinding. Where is the best place for calling DataBind method? Is it possible to say don't bind controls for this postback and use current values instead? These...
0
2139
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i have a gridview which displays the results of the search. if no search is entered, then the gridview shows all records. Below the gridview i have a formview for inserting and editing the records. when a user clicks on one of the records in the...
5
4681
by: =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post by:
Hi All, I have a GridView inside the EditItemTemplate of a FormView. Both FormView and GridView are data bound using an ObjectDataSource. When the FormView's ObjectDataSource object has a SelectParameters with a SessionParameter in the parameters collection and the object stored in the Session is a reference type, the DataGrid fails to enter Line Editing mode. Is this a bug? Is there a workaround for this problem?
1
229
by: shapper | last post by:
Hello, I have a GridView and I an ASP.NET panel with various controls which is a form. I need to fill the form controls with the values of the gridview record that was clicked. I will need not only the values visible in the GridView but also all the other values including the PK.
1
1428
by: DAnDA | last post by:
Hey i binding gridview/formview using one sqlDataSource,, that mean formview show all details from gridview selected row,,, now i cant use paging property for formview ,,, can anyone show me how to use paging formview ?!
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.