C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




doubt to add entire column value to a textbox in vb.net


Posted Date: 29 Aug 2008      Total Responses: 3

Posted By: G.Hemadribabu       Member Level: Gold     Points: 1


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




Responses

Author: ANIL PANDEY    29 Aug 2008Member Level: DiamondRating:     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 2008Member Level: GoldRating:     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 2008Member Level: SilverRating:     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)
}
//
}
}



Post Reply
You must Sign In to post a response.
Next : How i Load My Application When the System Restarts
Previous : Displaying Data randomly
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use