I have grid as follows
| Sr No | Min Value | Max Value |
| 1 | 1 | 500 |
| 2 | 501 | 700 |
I have two text box 1.Min Value 2.Max Value
and one add button
Now i want that first i enter min value as 1 and max as 500
when next time i enter the values Min value should automatically displayed as 501 as shown above
(i.e last Max Value + 1)
how to do it im using following code to add values to grid
protected void BtnAdd_Click(object sender, EventArgs e)
{
DataTable obj = GetEmptyTable();
foreach (GridViewRow gvRow in this.gv.Rows)
{
obj.Rows.Add(
this.gv.DataKeys[gvRow.RowIndex].Values["MinValue"],
this.gv.DataKeys[gvRow.RowIndex].Values["MaxValue"],
gvRow.Cells[1].Text,
gvRow.Cells[2].Text);
}
obj.Rows.Add(
this.TextBox1.Text,
this.TextBox2.Text, );
this.gv.DataSource = obj;
this.gv.DataBind();
}
and getemptyTable is private static DataTable GetEmptyTable()
{
var obj = new DataTable();
obj.Columns.Add("MinValue");
obj.Columns.Add("MaxValue");
return obj;
}
Please Help
Mukesh Kumar TiwariPosted Nov 15, 2013, 11:37 PM
ya i have checked that code is nt working.....
Try this....this time i have implement and then i m sending...so dnt wry...this will be work definetly......
And at the place of cells[1],cells[2]..write ur cell index of value...
int n = grid_OAF.Rows.Count;
double sum = 0;
double sum1 = 0;
public void add_Value()
{
for (int i = 0; i < n; i++)
{
double d = 0;
double c=0;
Double.TryParse(grid_OAF.Rows[i].Cells[1].Value.ToString(), out d);
Double.TryParse(grid_OAF.Rows[i].Cells[2].Value.ToString(), out c);
sum += d;
sum1+=c;
lbl_item_amt.Text = sum.ToString();
lbl_item_amnt_2nd.text=sum1.ToString();
}
}
all the best...
and dnt tell me sir...yar...
piyusha patravaliPosted Nov 16, 2013, 6:41 AM
piyusha patravaliPosted Nov 15, 2013, 8:39 AM
Mukesh Kumar TiwariPosted Nov 15, 2013, 7:27 AM
try this..........
int n = gridview1.Rows.Count;
for(int i=0;i <=n;i++)
{
//geting the valaue from grid
int a = (int)gridview1.Rows[i].Cells[1].value;
int b = (int)gridview1.Rows[i].Cells[2].value;
//Addition of value which we get from grid
int min = min + a;
int max = max + b;
a = 0; b = 0;
}
it will work sure......
all the best