Need to append rows in DataGrid from session variable. SQL Database involved.

In my Web Form, I have a TreeView and a DataGrid. When a user selects a node from the tree, an SQL query retrieves related values from the Database and populates a row in the grid. The user will be selecting multiple nodes, so I need the rows appended to grid, not overwriting previous ones. Also need to be able to delete a row from the grid if the user chooses. I have been cobbling together bits of code from many forums to use session variables, but cant seem to get it to work. As soon as I code anything relating to a session variable the grid stops populating. If I remove the "session stuff" , then the grid works fine, but each row gets overwritten with the next node selection.  My code is below. Thanks in advance for any help. (I am still fairly new to asp.net)

aspx:
 <telerik:RadGrid ID="RadGrid1" runat="server" 
                         
                         AutoGenerateColumns="False"   Skin="Telerik" OnDeleteCommand="RadGrid1_DeleteCommand"  AutoPostBack="true"> 
                        <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
                        <MasterTableView  DataKeyNames="ID" HorizontalAlign="NotSet" AutoGenerateColumns="False">
                        <FooterStyle CssClass="gridFooter"></FooterStyle>
                        <NoRecordsTemplate>
                            Setup / PDI items...
                        </NoRecordsTemplate>
                        <Columns>
                             <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" Visible="false">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="JobCode" HeaderText="Job Code" UniqueName="JobCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Price" HeaderText="Price" DataFormatString="${0}" UniqueName="Price">
                            </telerik:GridBoundColumn>
                            <telerik:GridButtonColumn ConfirmText="Delete this selection?" ConfirmDialogType="RadWindow"
                                ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px"
                                 CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                                <HeaderStyle Width="50px"></HeaderStyle>
                            </telerik:GridButtonColumn>
                        </Columns>
                      </MasterTableView>
                      </telerik:RadGrid>

Open in new window


cs:
protected void RadTreeView1_NodeCheck(object o, RadTreeNodeEventArgs e)
        {
            RadTreeNode node = e.Node;
            int val = Convert.ToInt32(node.Value);

            #region
            string JobCode = null;
            string Price = null;
            string ID = null;

            dtJC = (DataTable)Session["JobCodeGrid"];

            string selectquery = @"SELECT ID, JobCode, Price FROM Product WHERE ID = @ID";
            SqlCommand cmds = new SqlCommand(selectquery);          
            cmds.CommandType = CommandType.Text;
            cmds.Parameters.AddWithValue("@ID", val);
            con.Open();
            SqlDataReader rdr = cmds.ExecuteReader();
            while (rdr.Read())
            {
                JobCode = rdr["JobCode"].ToString();
                Price = rdr["Price"].ToString();
                ID = rdr["ID"].ToString();
            }
            con.Close();
            DataRow drow = dtJC.NewRow();
            drow[ID] = ID;
            drow[JobCode] = JobCode;
            drow[Price] = Price;
            RadGrid1.DataSource = dtJC;
            RadGrid1.DataBind();
            Session["JobCodeGrid"] = dtJC;

Open in new window

hhnetworksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Obadiah ChristopherDeveloper User InterfaceCommented:
Before this line,

RadGrid1.DataSource = dtJC;

add this

dtJC.Rows.Add(drow);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hhnetworksAuthor Commented:
Obadiah,

I added the line you recommended, but it has not helped yet. This morning, after debugging my code, Im realizing that the line with  SqlDataReader rdr = cmds.ExecuteReader(); is the last line executed. The 'while' statement and everything below it does not execute. No error messages.
Any ideas? Thanks again.
Obadiah ChristopherDeveloper User InterfaceCommented:
Try adding a try catch block. I guess there is an error in your connection to the database.

As per ur code, there is no try catch block.
hhnetworksAuthor Commented:
Thanks for your help.  I am closing the question. I did find errors in the construction of my data table, and SQLDataReader statements. Your first reply regarding "dtJC.Rows.Add(drow);" did point me in the right direction. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.