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


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

if condition bofore binding data in gridview

Posted By: Catherine     Posted Date: June 15, 2011    Points:5   Category :C#
hi i bind employee details in gridview.such as name,id,account number. before bind data in gridview i would like to check if(account.length==12)
{
accnum=00+accnum
}
else if(account.length==13)
{
accnum=0+accnum
}

how to use and bind in gridview. please tell

Responses
Author: Gowthammanju             
Posted Date: June 15, 2011     Points: 20   

for binding in grid view use cosing as

gridview1.datasource=ds
gridview1.databind()



where gridview1 is the gridview name....

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: June 15, 2011     Points: 20   

for that u can use validation while feeding the data in to database know

check for validation in c#

try it

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: June 15, 2011     Points: 20   

hey for bank account number try following codings


// A bank account number consists of 9 or 10 digits
if (!(cleanAccNumber.Length == 9 || cleanAccNumber.Length == 10)) return false;

// ... all being numeric and not resulting in a 0 when converted to a number ...
long l;
if (!long.TryParse(cleanAccNumber, out l)) return false;
if (l == 0) return false;

// pad it to the left to 10 digits with preceding zero's.
cleanAccNumber = cleanAccNumber.PadLeft(10, '0');

// ... the number must be validatable to the so-called 11-proof ...
long total = 0;
for (var i = 1; i <= cleanAccNumber.Length; i++)
{
// 11-proof for 10 digit bank account numbers (bron: Wikipedia): (1*A + 2*B + 3*C + 4*D + 5*E + 6*F + 7*G + 8*H + 9*H + 10*I) % 11 == 0
var number = Convert.ToInt32(cleanAccNumber[i - 1].ToString());
total += number*i;
}

// ... not result in a 0 when dividing by 11 ...
if (total == 0) return false;

// ... and not have a modulo when dividing by 11.
return total % 11 == 0;


Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Sasi Prabhu             
Posted Date: June 16, 2011     Points: 20   

Use Stored Procedure.

Thanks & Regards,
Sasi Prabhu.
Author: shiv chandra             
Posted Date: June 16, 2011     Points: 20   

// Please change "dtSample" with your actual DataTable
DataTable dtSample = new DataTable();
for (int i = 0; i < dtSample.Rows.Count; i++)
{
if (dtSample.Rows[i]["account"].ToString().Length == 12)
{
dtSample.Rows[i]["account"] = "00" + accnum;
}
else if (dtSample.Rows[i]["account"].ToString().length == 13)
{
dtSample.Rows[i]["account"] = "0" + accnum;
}
}

// After above process bind dtSample as your datasource


Regards
Shiva
Author: Narayanan             
Posted Date: July 12, 2011     Points: 20   

Hi,
Use Information based on your conditional statement.
select * from table_Name where LENGTH(AccountNo) = 12



Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


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