| | |
adding the values to the grid dynamically and with unique id
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
aspnet Syntax (Toggle Plain Text)
private void AddRecordToGrid() { try { datatable dt = new datable(); if (Session["SampleDataTable"] == null) { dt.Columns.Add(new DataColumn("ID", typeof(string))); dt.Columns.Add(new DataColumn("Qtr", typeof(string))); dt.Columns.Add(new DataColumn("Exp", typeof(string))); dt.Columns.Add(new DataColumn("Partner", typeof(string))); dt.Columns.Add(new DataColumn("Net", typeof(string))); dr = dt.NewRow(); } else { dt= (DataTable)Session["SampleDataTable"]; } dr = dt.NewRow(); if (dr.IsNull(0)) { //dr = dt.NewRow(); dr[0] = txtD.Text; dr[1] = cbQuarter.SelectedItem.Text; dr[2] =Exp.Text; dr[3] = txtPartner.Text; dr[4] = lblNet.Text; dt.Rows.Add(dr); DataView dv = new DataView(dt); grdBudget.DataSource = dv; grdBudget.DataBind(); } for (int i = 0; i < grdBudget.Rows.Count; i++) { if (!dr.IsNull(0)) { if (txtBudgetID.Text != dr[0].ToString()) { dr = dt.NewRow(); dr[0] = txtD.Text; dr[1] = cboQuarter.SelectedItem.Text; dr[2] = Exp.Text; dr[3] = txtPartner.Text; dr[4] = lblNet.Text; dt.Rows.Add(dr); DataView dv = new DataView(dt); grdBudget.DataSource = dv; grdBudget.DataBind(); } } } Session["SampleDataTable"] = dt; } catch (Exception ex) { }
the problem i m facing wid this code id that the new data row is added every time when this function is called and it enters ito the loop of the if(dr.isnull(0)) . i want only the values with unique id shud be entered. if the value wid the existin id id entere, it shud not be allowed to enter.
Last edited by cscgal; Nov 6th, 2008 at 12:18 pm. Reason: Added code tags
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Error for UpdateQuery from Visual Studio 2008
- Next Thread: Compatibility Issue on Firefox for freetextbox to display on Cursor Location
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv gridview gudi iis javascript list listbox login menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





