Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my asp
XML
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server"
            onrowdatabound="GridView1_RowDataBound" DataKeyNames="head_code" >
        </asp:GridView>

    </div>
    </form>
</body>



This is my code.
C#
protected void Page_Load(object sender, EventArgs e)
   {
       hitechLatestEntities database = new hitechLatestEntities();
       GridView1.DataSource = database.HEADs;

       TemplateField tfObject = new TemplateField();
       tfObject.HeaderText = "Sub-Heads Details";

       tfObject.ItemTemplate = new WebForm1(ListItemType.Item);
       GridView1.Columns.Add(tfObject);
      GridView1.DataBind();
   }

I want this recently added column at right most place of the gridview1. For now it is appearing at left most.
Posted
Updated 29-Jan-14 2:08am
v3
Comments
Karthik_Mahalingam 29-Jan-14 7:23am    
post your gridview code. aspx
Basit Elahi 29-Jan-14 7:38am    
<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound" DataKeyNames="head_code" >


I am doing most of the work programatically
Karthik_Mahalingam 29-Jan-14 7:58am    
post full gridview code..
Basit Elahi 29-Jan-14 8:05am    
i have updated the question. please check it
Karthik_Mahalingam 29-Jan-14 8:07am    
so everything you are adding in code behind only ??
how many columns ??

please try and set gridview.column.display index


Hi, sorry for my answer. display index is i think used in window applicatio not web application.

in web site you can chek below link .

http://stackoverflow.com/questions/8976153/how-to-reorder-columns-in-gridview-dynamically
 
Share this answer
 
v2
Comments
Basit Elahi 29-Jan-14 7:50am    
can u give me some example ravikhoda??
try like this..

C#
DataControlFieldCollection allcolumns =  GridView1.Columns;
         GridView1.Columns.Clear();
         GridView1.Columns.Add(allcolumns[0]);  // you can change the index in which order u need to display
         GridView1.Columns.Add(allcolumns[1]);
         GridView1.Columns.Add(allcolumns[2]);
         GridView1.Columns.Add(allcolumns[3]);
         GridView1.DataBind();
 
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