.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!



Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Gridview Current Cell Value

Posted By: Aamrapali Tamgadge     Posted Date: February 22, 2011    Points:2   Category :ASP.Net
hi.Me having One Gridview In dat m having ten textboxes in each row, m Performing the calulation of total Quantity and Total Rupees according these textboxes..But My conditon is dat total is not exceeded by 1000 if it is greater than thousand den on click event it show the message dat your have no money to play..den it should restict the user to enter any amount in textboxes how can i do this how can i find the exactly the current textbox in gridview and den focus on it ..


Responses
Author: Sunil Yadav       [Moderator]      
Posted Date: February 23, 2011     Points: 5   

Hi,

On GridviewRowDataBound event you can write a code to find the textboxes in a gridvoiew row cell.

On text box change event of every text box calculate the total amount.

If you find amount greater than 1000 then prompt a message .

To find the text box in the gridview you can refer the code logic written below.

TextBox txt1=new TextBox();
txt1.TextChanged+=new EventHandler(CalculateTotal);
//Similarly attach an event handler to all the text boxes.

//Find control here
protected void gvQuestions_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
txt1 = (TextBox)e.Row.Cells[0].FindControl("txt1");
}
}

protected void CalculateTotal(object sender, EventArgs e)
{
txt = sender as TextBox;
// Here calculate the total amount based on the value captured from textbox.
}


Let me know if you need any help.

Author: Aamrapali Tamgadge             
Posted Date: February 23, 2011     Points: 5   

Hello I have write the code under rowdatabound event but this event is get fired only wen the page loading.. but wen i change the textboxes value how can i find in which textbox i have enter the value

Software Programmer At OTIS ISRC
Author: Sunil Yadav       [Moderator]      
Posted Date: February 23, 2011     Points: 5   

Hi Aamrapali,

In the above code the RowDataBound is used to find the text box in the gridview cell.

Once you find the controls(TextBox), attached TextChanged event handler. This will give you a current text box which triggered an TextChanged event.

Consider below code.

protected void CalculateTotal(object sender, EventArgs e)
{
txt = sender as TextBox; //Gets the reference to the current textbox.

}


Let me know if have any more doubts.



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend