Click here to Skip to main content
13,005,843 members (89,416 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi everybody,

I have a gridview in my gridview i display the data whatever i want. That's totally completed except small point. I want to display serial numbers at first column. I know how to give serial number but i need in below format. Can any one help me out of this.

SNo       Material          Grade
1         RCC               M30
1.a                         M50
1.c                         M70
2         FormWork          column
2.a                         Plates

Can any one give me some suggestion to achieve my serial number in above format.



Thanks in Advance
Posted 25-Jul-13 21:58pm
Comments
Shraddha R Kad 26-Jul-13 5:30am
   
on what condition you want to display sno
VishwaKL 26-Jul-13 6:03am
   
what is the condition to make serial number. use that condition and generate the sl no
N@veen.S 26-Jul-13 6:24am
   
hi, here material_id is repeated more than once then i want to show the 1.a , 1.b ... based on repetation. How to do...
VishwaKL 26-Jul-13 7:31am
   
so you saying material_id is the condition, before binding the values to grid check the material_id apply the logic for generating sl.no and bind the values to grid view
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Here is a small function that might help you

private void generateSLNo(int totalRow)
    {
        List<string> li = new List<string>();
        string s = string.Empty;
        for (int i = 1; i <= 10; i++)
        {
 
            for (int j = 96; j < 123; j++)
            {
                if (j == 96)
                {
                    s = s = Convert.ToString(i + ".");
                }
                else
                {
                    s = Convert.ToString(i + "." + (char)j);
                }
                li.Add(s);
                li.Add("<br>");
 
            }
           
        }
        s = string.Empty;
        for (int p = 0; p < li.Count; p++)
        {
            s = s + li[p].ToString();
 
        }
 
        lbl.Text = s;
    }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You can do this

<Columns>
 
<asp:CommandField ButtonType="Image" CancelImageUrl="~/data/commands/cancel.gif"
 
DeleteImageUrl="~/data/commands/delete.gif" DeleteText="Verwijder" EditImageUrl="~/data/commands/edit.gif"
 
EditText="Bewerk" SelectImageUrl="~/data/commands/download.gif" SelectText="Download bestand"
 
ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" UpdateImageUrl="~/data/commands/save.gif"
 
UpdateText="Opslaan">
 
<HeaderStyle Width="10%" />
 
</asp:CommandField>
 
<asp:BoundField HeaderText="No." ReadOnly="true">
 
<ItemStyle HorizontalAlign="Right" Width="1%" />
 
</asp:BoundField>
 

 
Then on the codebehing:
protected void gridLidDocument_RowDataBound(object sender, GridViewRowEventArgs e)
 
{
if (e.Row.RowType.Equals(DataControlRowType.DataRow))
 
{
 
e.Row.Cells[1].Text = "" + ((((GridView)sender).PageIndex * ((GridView)sender).PageSize) + (e.Row.RowIndex + 1));
 
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 26 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100