Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
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
Naveen.Sanagasetti 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

Here is a small function that might help you

XML
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;
    }
 
Share this answer
 
You can do this

C#

XML
<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));

}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900