Navigation in Gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murugavelmsc
    New Member
    • Apr 2008
    • 54

    Navigation in Gridview

    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.T his 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

    Code:
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default4.aspx">New</asp:HyperLink>
            &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;
            <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/Default4.aspx">Open</asp:HyperLink><br />
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="4" DataSourceID="SqlDataSource1"
                ForeColor="#333333" GridLines="None" PageSize="5" AllowSorting="True" Caption="Book Details" CaptionAlign="Top" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="Job_ID">
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"  />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:CommandField/>
                    <asp:HyperLinkField DataNavigateUrlFields="Job_ID" DataNavigateUrlFormatString="Default4.aspx?JID={0}" Text="Open" />
                    <asp:HyperLinkField DataNavigateUrlFields="Job_ID" DataNavigateUrlFormatString="Default4.aspx?JID={0}" Text="Create batch" />
                </Columns>
                
                
            </asp:GridView>
            
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pmgConnectionString %>"
                SelectCommand="SELECT [Job_ID], [Project_Manager], [Book_Name], [Job_Source], [Work_Type], [Software], [Job_Type], [Complexity], [Priority], [Publisher] FROM [book]"></asp:SqlDataSource>
            
        </div>
        </form>
    </body>
    secondpage.aspx .cs

    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            string cid;
            cid= Request.QueryString["JID"];
    
            Response.Write(cid);
    
            SqlConnection dbcon = new SqlConnection("Data source=localhost;initial catalog=pmg;integrated security=true");
            //dbcon.Open();
            SqlCommand co2 = new SqlCommand("select book_name from book where job_id= '"+cid+"' ", dbcon);
            co2.Connection.Open();
            SqlDataReader dr = co2.ExecuteReader(); 
            
            //co2.ExecuteNonQuery();
            //rd = co2.ExecuteReader();
            if (dr.HasRows == true)
            {
                TextBox1.Text =dr["book_name"].ToString();
            }
    
           dr.Close();
           dbcon.Close();
    
        }
    thanks in advance,
    murugavel
    Last edited by Curtis Rutland; Aug 12 '08, 04:32 AM. Reason: Added code tags -- Please use the # button
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    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

    Comment

    Working...