hi ,
I had posted my doubt yesterday for the below mentioned problem
I have a search type , where the user fill's as per his request and clicks the button, on clikc of the button the records are shown in gridview in VB.NET. .The code i written for this is below ______________________________________________________
con.Open() dt.Rows.Clear() Dim sqlcmd As New OleDbCommand("Select * from admintable Where [DATE] between '" & frdt.Text & "' and '" & todt.Text & "' And SUBACCOUNT = '" & subacc.SelectedItem & "'", con) Dim da As New OleDbDataAdapter da.SelectCommand = sqlcmd da.Fill(dt) DataGridView1.DataSource = dt Me.AdmintableTableAdapter.Fill(Me.ADDS.admintable) da.Dispose() con.Dispose() con.Close() _____________________________________________________
Now i have got totaoly of 5 columns and in tht one column name = AMOUNT has to be calculated in the gird, and store tht in the textbox1.text
so for tht i have written code like this
_________________________________________ For Each grvRow As DataGridViewColumn In DataGridView1.Rows TextBox1.Text = TryCast(grvRow.Cells(1).FindControl("Number"), TextBox) Dim amount As Integer amount += TextBox1.Text Next
__________________________________________
For this calculating sake i am getting error , it is not suming the values present in the gird and placing in the textbox,
pls give me the code for adding tht amount column alone and store in the gridview
very urgetn pls help me
|
| Author: ANIL PANDEY 29 Aug 2008 | Member Level: Diamond | Rating: Points: 6 |
Hi,
hello u can use the Row Data Bound Event to calculate the Sum of Each Row.. here u can get the cell values..
like..
protected void grdLeaves_RowDataBound(object sender, GridViewRowEventArgs e) { Label lblDays; Label lblFrom; Label lblTo; TimeSpan tsDay;
if (e.Row.RowType == DataControlRowType.DataRow) { lblFrom = (Label)(e.Row.FindControl("lblDateFrom")); lblTo = (Label)(e.Row.FindControl("lblDateTo")); lblDays = (Label)(e.Row.FindControl("lblDays"));
//Calulating the no of days DateTime dtFrom = Convert.ToDateTime(lblFrom.Text.ToString()); DateTime dtTo = Convert.ToDateTime(lblTo.Text.ToString());
lblFrom.Text = dtFrom.ToShortDateString().ToString(); lblTo.Text = dtTo.ToShortDateString().ToString();
//tsDay = dtTo.Subtract(dtFrom); //if (tsDay.Days == 0) //{ // lblDays.Text = "1"; //} //else //{ // lblDays.Text = tsDay.Days.ToString(); //}
} }
Thanks Anil
|
| Author: Praveen 29 Aug 2008 | Member Level: Gold | Rating: Points: 4 |
in rowDataBound Event Try like this Dim dgItem as DataGridItem Dim TotAmount as Integer // Suppose ur pasting the value of Amount in a label called lblAmount Foreach (dgItem in dgLeave.Items) TotAmount=TotAmount +CInt(DirectCast(dgItems.FindControl("lblAmount"),Label).Text) Next
Now in ur textbox place that TotAmount
I Hope this will help u
|
| Author: Legend 29 Aug 2008 | Member Level: Silver | Rating: Points: 6 |
You try this code to add the ADD The column
\ string res=""; string d="";
Database connection here// if (ds1 != null) { //check if (ds1.Tables.Count > 0) { foreach (System.Data.DataRow check in ds1.Tables[0].Rows) { d = check["Days"].ToString(); Int32 day = Convert.ToInt32(d); ress = day + ress;//Here you can get total (adding value) } // } }
|