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
secondpage.aspx .cs
thanks in advance,
murugavel
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> <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>
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(); }
murugavel
Comment