GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  DataGrid
Go To First  |  Previous Question  |  Next Question 
 DataGrid  |  Question 13 of 14    Print  
Data grid Serial Number
How to add Serial Number in the data grid dynamically, Windows application, using C#


  
Total Answers and Comments: 2 Last Update: March 26, 2009     Asked by: sekaranpg 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 28, 2007 07:41:30   #1  
msg2mano Member Since: November 2007   Contribution: 2    

RE: Data grid Serial Number
//try this coding ---this may help u i thing
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace CSharp
{
public partial class Form1 : Form
{
SqlConnection con;
SqlCommand com;
SqlDataAdapter da;
DataTable dt new DataTable();
//DataSet ds new DataSet();
int i 0;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender EventArgs e)
{
DgBind();//call datagrid bind function
}
public void DgBind()//datagrid bind function
{
try
{
string constr (string)ConfigurationSettings.AppSettings["constr"];
con new SqlConnection(constr);
com new SqlCommand("select * from student" con);
da new SqlDataAdapter(com);
da.Fill(dt);
dataGrid1.DataSource dt;
addcol();//call addcolumn(srno) function

}
catch (Exception ex)
{

}
}

public void addcol()//addcolumn(srno) function
{

DataColumn col1 new DataColumn();
col1.ColumnName "srno";
dt.Columns.Add(col1);
foreach (DataRow row in dt.Rows)
{
foreach (DataColumn col in dt.Columns)
{
if (col.ToString() "srno")
{
row.BeginEdit();
i+ 1;
row["srno"] i ;
row.EndEdit();
}
}
}
dataGrid1.DataSource dt;
}
}
}

 
Is this answer useful? Yes | No
March 25, 2009 02:03:08   #2  
nt57323 Member Since: March 2009   Contribution: 9    

RE: Data grid Serial Number
I am providing the solution in ASP. Just convert this as you like.
I have tried
this one at my end and its working fine.
Just take one Template field as
Serialno. in Datagrid.
Below is the code in HTML:

< size 2>asp: size 2>TemplateField HeaderText color #0000ff size 2> Sl.no size 2>HeaderStyle-ForeColor size 2> White >

<
size 2>ItemTemplate>

<
size 2>asp: size 2>Label ID size 2> lblslno size 2>runat server color #ff0000 size 2>Text ' size 2>< # Slcount() > size 2>'></asp size 2>:Label size 2>>

</
size 2>ItemTemplate>

</
asp color #0000ff size 2>: size 2>TemplateField>


Slcount() is the function which i have taken in the code page.

Take one variable Count as integer.

In the above function take Count Count + 1. Initially count will be taken as
Zero.

Below is the code in the code page:


Dim
count
as
integer
0

Public Function
Slcount()
as
Integer

count

count
+
1

Return
count

End Function


Enjoy Coding.



 
Is this answer useful? Yes | No

 Related Questions

In DataGrid, is it possible to add rows one by one at runtime. That means after entering data in one row next row will be added.

Latest Answer : refresh datagrid by calling it in postback ...
Read Answers (10) | Asked by : Prajakta Deshpande

Hi, How to sort the data in gatagrid ? when we use DataBound event of Datagrid,,,, I want to display the data using controls.... For an example, If i click a button, which is outside of the datagrid, entire data should be shown. 1st column in TextBoxs. second column in Drop down List Boxs.. How to bind the data in Dropdownlist,which is in DataGrid at run time?
Read Answers (1) | Asked by : Ravi Majji

Hi, How to sort the data in Datagrid ? when we use DataBound event of Datagrid, I want to display te data using controls.... For an example, If i click a button, which is outside of the datagrid, entire data should be shown. 1st column in TextBoxs. second column in Drop down List Boxs.. How to bind the data in Dropdownlist,which is in DataGrid at run time? Row1 Row2 Row3 Row4 ----------------- This is the record in datagrid...
Read Answers (2) | Asked by : aspnet

How to get the content of Datagrid into excel format?I want to use this feature in Windows Application and C#, Visual Studio .NET 2003 
Latest Answer : for windows application u use excel object to create excel file ...

How to add Serial Number in the data grid dynamically, Windows application, using C# 
Latest Answer : I am providing the solution in ASP. Just convert this as you like.I have tried this one at my end and its working fine.Just take one Template field as Serialno. in Datagrid. Below is the code in HTML:


 Sponsored Links

 
Related Articles

Breaking up XML into Relational Data

Breaking up XML into Relational Data While the preceding example shows how to construct an XML representation over relational data the example in this section illustrates how you can shred XML data back into relational data This reverse operation can be useful if your application works with relation
 

Querying Data with Oracle XQuery

Querying Data with Oracle XQuery Starting with Oracle Database 10g Release 2 you can take advantage of a full featured native XQuery engine integrated with the database With Oracle XQuery you can accomplish various tasks involved in developing PHP Oracle XML applications operating on any kind of dat
 

Retrieving XML Data

Retrieving XML DataTo retrieve XML data from an XMLType table you can use a SELECT SQL statement just as you would if you had to query a relational table For example to select the employee with the id set to 100 from the employees XMLType table discussed in the preceding section you might issue the
 

Using XMLType for Handling XML Data in the Database

Using XMLType for Handling XML Data in the Database Being an object type XMLType can not only be used to store XML data in the database but also to operate on that data via its built in methods Regardless of the storage model you choose XMLType provides a set of XML specific methods to operate on XM
 

Using Oracle Database for Storing, Modifying, and Retrieving XML Data

Using Oracle Database for Storing Modifying and Retrieving XML Data With Oracle XML DB you have various XML storage and XML processing options allowing you to achieve the required level of performance and scalability One of the most interesting things about Oracle XML DB is that it allows you to per
 

ODP.NET - Techniques to Improve Performance while Retrieving Data

ODP NET Techniques to Improve Performance while Retrieving Data Performance tuning is a great subject in Oracle Volumes of books would not be enough to cover every aspect of performance tuning in Oracle However in this section we will only discuss the fundamental performance techniques while working
 

ODP.NET - Populating a Dataset with a Single Data Table

ODP NET Populating a Dataset with a Single Data Table A dataset is simply a group of data tables These data tables can be identified with their own unique names within a dataset You can also add relations between data tables available in a dataset mosgoogle The following code gives you the details o
 

ODP.NET - Retrieving Typed Data

ODP NET Retrieving Typed Data While retrieving values from OracleDataReader we can extract information available in individual columns of a particular row either by using column ordinal position values or column names mosgoogle Retrieving Typed Data Using Ordinals ODP NET provides data specific enum
 

ODP.NET - Retrieving Multiple Rows on to the Grid

ODP NET Retrieving Multiple Rows on to the Grid In the previous section we tried to retrieve only one row using OracleDataReader In this section we will try to retrieve more than one row or a result set and populate a DataGridView on a WinForm mosgoogle The following code lists out the details of al
 

ODP.NET - Retrieving Data Using OracleDataReader

ODP NET Retrieving Data Using OracleDataReader OracleDataReader is simply a read only and forward only result set It works only if the database connection is open and it makes sure that the connection is open while you are retrieving data As the data that it retrieves is read only it is a bit faster
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape