473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Navigation in Gridview

54 New Member
hi,
i am using two pages, the first page contains the gridview control which i select one record means that job id of particular record move to second page through querystring. But in second page i have a design like form of textboxes and dropdownboxes.This control are filled depend on the job id which i select from first page.

i try the below mentioned code, it throw an error like "Invalid attempt to read when no data is present."

first.aspx

Expand|Select|Wrap|Line Numbers
  1. <body>
  2.     <form id="form1" runat="server">
  3.     <div>
  4.         <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default4.aspx">New</asp:HyperLink>
  5.         &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;
  6.         <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/Default4.aspx">Open</asp:HyperLink><br />
  7.         <asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="4" DataSourceID="SqlDataSource1"
  8.             ForeColor="#333333" GridLines="None" PageSize="5" AllowSorting="True" Caption="Book Details" CaptionAlign="Top" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="Job_ID">
  9.             <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  10.             <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  11.             <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  12.             <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"  />
  13.             <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  14.             <EditRowStyle BackColor="#999999" />
  15.             <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  16.             <Columns>
  17.                 <asp:CommandField/>
  18.                 <asp:HyperLinkField DataNavigateUrlFields="Job_ID" DataNavigateUrlFormatString="Default4.aspx?JID={0}" Text="Open" />
  19.                 <asp:HyperLinkField DataNavigateUrlFields="Job_ID" DataNavigateUrlFormatString="Default4.aspx?JID={0}" Text="Create batch" />
  20.             </Columns>
  21.  
  22.  
  23.         </asp:GridView>
  24.  
  25.         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pmgConnectionString %>"
  26.             SelectCommand="SELECT [Job_ID], [Project_Manager], [Book_Name], [Job_Source], [Work_Type], [Software], [Job_Type], [Complexity], [Priority], [Publisher] FROM [book]"></asp:SqlDataSource>
  27.  
  28.     </div>
  29.     </form>
  30. </body>
  31.  
secondpage.aspx.cs

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         string cid;
  4.         cid= Request.QueryString["JID"];
  5.  
  6.         Response.Write(cid);
  7.  
  8.         SqlConnection dbcon = new SqlConnection("Data source=localhost;initial catalog=pmg;integrated security=true");
  9.         //dbcon.Open();
  10.         SqlCommand co2 = new SqlCommand("select book_name from book where job_id= '"+cid+"' ", dbcon);
  11.         co2.Connection.Open();
  12.         SqlDataReader dr = co2.ExecuteReader(); 
  13.  
  14.         //co2.ExecuteNonQuery();
  15.         //rd = co2.ExecuteReader();
  16.         if (dr.HasRows == true)
  17.         {
  18.             TextBox1.Text =dr["book_name"].ToString();
  19.         }
  20.  
  21.        dr.Close();
  22.        dbcon.Close();
  23.  
  24.     }
thanks in advance,
murugavel
Aug 12 '08 #1
1 1472
Curtis Rutland
3,256 Recognized Expert Specialist
This is your third warning about using code tags. Your second was here and your first was here. If you neglect to do this again, you will be temporarily banned from this site.

We have these rules for a reason. Large blocks of code are difficult to read, and the code tags preserve whitespace and spacing. It makes it much easier to read the code. And if experts can read your code, then they can help you. If it is hard, they might ignore you.

Read the Posting Guidelines. This is your last warning.

MODERATOR
Aug 12 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Veli-Pekka Tätilä | last post by:
Hi, My first post here. I've found some serious accessibility flaws in the Python 2.4 docs and wish they could be rectified over time. I'm very new to Python and initially contacted docs at python...
3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
0
by: Sam | last post by:
I am fairly new to ASP. Net 2.0, background MS Access 2000/2003 and working knowledge of SQL 2000. Scenario: Page1: Blank Page loads with 2 Text Boxes (TxtLast, TxtFirst), a Command...
3
by: Paul | last post by:
I want the <div id="navigation"column to be the same color all the way to the bottom. The "background-image: url(bg_menu_tile.gif);" was a try to force it with a long 1-pixel graphic - didn't...
10
by: EA | last post by:
I am sure I must be missing something about building navigation bars with CSS. Yes it is a very clever and efficient way to format navigation structures on simple one navigation level webs, i.e....
1
by: mani.shanku | last post by:
hi friendsplz..help me its urgent..... im making a jobportal site..when a person go for search the results should desplay.... like the naukri.com desplays..and when a person click on the checkbox...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
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...

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.