Hey everyone,
I have a grid,its data source is a data table.I've created columns in the data table.and at page_load grid is visible with no records in it & just names of the columns.Now,I've a button external to the grid which i am using to open up the insert Form.I've created form template for inserting values.It also have 2 buttons Save and Cancel.
Now,on Save button I put all the values inserted by the user in the first row of the data table.And it is visible in the data Table when i see using breakpoints.But My problem is that it remains in the Data Table and is not Visible in the Grid.I want Grid to show values inside the data Table and values keeps on increasing as user inserts more items to the Data Table.
My code for CS is--
What's wrong with this,Am i missing something OR is this NOT POSSIBLE to insert temporary items to grid using data Table as Data Source.Plz help...
Thanks
Amit
I have a grid,its data source is a data table.I've created columns in the data table.and at page_load grid is visible with no records in it & just names of the columns.Now,I've a button external to the grid which i am using to open up the insert Form.I've created form template for inserting values.It also have 2 buttons Save and Cancel.
Now,on Save button I put all the values inserted by the user in the first row of the data table.And it is visible in the data Table when i see using breakpoints.But My problem is that it remains in the Data Table and is not Visible in the Grid.I want Grid to show values inside the data Table and values keeps on increasing as user inserts more items to the Data Table.
My code for CS is--
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { dtValues = new DataTable(); dtValues.Columns.Add("Items"); dtValues.Columns.Add("Rate"); dtValues.Columns.Add("Quantity"); dtValues.Columns.Add("Amount"); RadGrid1.DataSource = dtValues; }protected void btnAdd_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.IsItemInserted = true; RadGrid1.MasterTableView.Rebind(); }protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) { GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item; RadComboBox combo = insertItem.FindControl("RadComboBox1") as RadComboBox; combo.AutoPostBack = true; combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged); Button Save = insertItem.FindControl("btnSave") as Button; Save.Click += new EventHandler(Save_Click); Button cancel = insertItem.FindControl("btnCancel") as Button; cancel.Click += new EventHandler(Cancel_Click); } }protected void Cancel_Click(object sender, EventArgs e) { Button Cancel = (Button)sender; GridEditFormInsertItem insertItem = (GridEditFormInsertItem)Cancel.NamingContainer; RadComboBox combo = insertItem.FindControl("RadComboBox1") as RadComboBox; Label lblRate = (Label)insertItem.FindControl("lblRate"); RadNumericTextBox txtQauntityE = (RadNumericTextBox)insertItem.FindControl("txtQuantityE"); Label lblAmount = (Label)insertItem.FindControl("lblAmount"); combo.SelectedIndex = -1; lblRate.Text = ""; txtQauntityE.Text = ""; lblAmount.Text = ""; RadGrid1.MasterTableView.IsItemInserted = false; RadGrid1.MasterTableView.Rebind(); } protected void Save_Click(object sender, EventArgs e) { Button Save = (Button)sender; GridEditFormInsertItem insertItem = (GridEditFormInsertItem)Save.NamingContainer; RadComboBox combo = insertItem.FindControl("RadComboBox1") as RadComboBox; Label lblRate = (Label)insertItem.FindControl("lblRate"); RadNumericTextBox txtQauntityE = (RadNumericTextBox)insertItem.FindControl("txtQuantityE"); Label lblAmount = (Label)insertItem.FindControl("lblAmount"); if (combo.SelectedIndex > 0 && txtQauntityE.Text != null) { DataRow drValues = dtValues.NewRow(); drValues["Items"] = combo.SelectedItem.Text; drValues["Rate"] = lblRate.Text; drValues["Quantity"] = txtQauntityE.Text; drValues["Amount"] = lblAmount.Text; dtValues.Rows.Add(drValues); dtValues.AcceptChanges(); RadGrid1.DataSource = dtValues; RadGrid1.Rebind(); RadGrid1.MasterTableView.IsItemInserted = false; RadGrid1.MasterTableView.Rebind(); } else { } }protected void combo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) { RadComboBox combo = (RadComboBox)o; GridEditFormInsertItem insertItem = (GridEditFormInsertItem)combo.NamingContainer; Label lblRate = (Label)insertItem.FindControl("lblRate"); SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["conn"].ToString()); SqlCommand cmd = new SqlCommand("select [Rate] FROM [tblProducts] where ProductName=@ProductName", conn); cmd.Parameters.Add(new SqlParameter("@ProductName", combo.SelectedValue)); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { lblRate.Text = ds.Tables[0].Rows[0].ItemArray.GetValue(0).ToString(); } RadNumericTextBox Quantity = (RadNumericTextBox)insertItem.FindControl("txtQuantityE"); Quantity.Focus(); }protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) { GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item; } }Thanks
Amit