Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am using code behind to bind my gridview and i would like to know how i can add an extra column to the gridview to allow user to select the row throw checkbox, also i want to change the header column title names, so can you guys help me please

ASP.NET
<asp:GridView ID="MailshwGRDVIW" runat="server" HeaderStyle-BackColor="#ffc809" BorderStyle="None"
                           AllowPaging="true" AlternatingRowStyle-BorderStyle="None"
                           HeaderStyle-ForeColor="White" Width="600px" HeaderStyle-Height="25px">



                           </asp:GridView>



C#
if (Session ["UsrNme"] != null)
          {
              string UsrNme = Convert.ToString(Session["UsrNme"]);

              DataTable MailshowDT = new DataTable();



              SqlConnection MailshowCon = new SqlConnection();
              String MailshowSQL = "SELECT sender, Mestitle, Date  FROM mails WHERE ([Receiver] = @Receiver)";

              using (SqlDataAdapter MailshowDA = new SqlDataAdapter(MailshowSQL, sc))
              {

                  MailshowDA.SelectCommand.Parameters.AddWithValue("@Receiver", UsrNme);
                  MailshowDA.Fill(MailshowDT);

              }


              MailshwGRDVIW.DataSource = MailshowDT;
              MailshwGRDVIW.DataBind();
          }
Posted

You can add a check box and set header text like below

XML
<Columns>
<asp:TemplateField  HeaderText="headettext" >
<ItemTemplate>
<asp:CheckBox ID="myCheckBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
 
Share this answer
 
Comments
Member 10690878 26-Jul-14 7:06am    
Hi @Hard_Rockz thanks for your reply but what about the 2nd part of my post about how i can change the header names of other columns from code behind
Dilan Shaminda 26-Jul-14 15:26pm    
Hi,sorry for the late reply.You can do it like this

myGrid.Columns[0].HeaderText = "Header Text";

Check these solutions as well

http://www.codeproject.com/Questions/421920/datagridview-headder-name-change

http://stackoverflow.com/questions/13013241/change-header-text-of-columns-in-a-gridview

http://stackoverflow.com/questions/3379581/how-can-i-programatically-change-the-headertext-of-my-gridview-columns-in-a-nest
I think you will get all that you need here.

GridView all in one[^]
 
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