Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,
I want to add check boxes to gridview dynamically I have google it but didnt found anything use full so please help me for this.
Thanks in advance
Posted

Hi,
You can add Dynamic Checkbox usnig TemplateField
like following
XML
<asp:TemplateField >
                                                                            <ItemTemplate>
                                                                                <asp:CheckBox ID="CheckBox1" runat="server" />
                                                                            </ItemTemplate>


Hope it will help u
best Luck
 
Share this answer
 
XML
Hi,

if you need this checkbox to appear for each DataSet, you can still use ItemTemplate in your GridView declaration.  Then you can add your dynamically created columns.

However, if you only need this checkbox is some cases, you needto add TemplateField column to your grid and assign ItemTemplate property.  You need to have instance of a class implementing ITemplate interface to assign it to ITemTemplate property.

To get this instnace you can:

    <div mce_keep="true">Create a UserContorl with CheckBox inside and load it using LoadTemplate method of your page</div>
    <div mce_keep="true">Use sample class and code from: http://couldbedone.blogspot.com/2007/07/implementing-itemplate-as-anonymous.html </div>
        <div mce_keep="true">This sample uses Button instead of CheckBox, just need to replace</div>
        <div mce_keep="true">This sample demonstrates implementation of ITemplate for GridView column</div>

Note, that if you have ViewState enabled for your GridView, you will probably lose your checkbox on postback.  So, this simple TemlateField sample works only for GridViews with disabled ViewState. If data binding on each postback is not acceptable for you, please ask more questions here.

Refer
http://www.webswapp.com/codesamples/aspnet20/itemplate/gridview.aspx[^]
 
Share this answer
 
foreach(gridviewrow gv in gridview.row)
{
Then by find contor get coloum no and add it
}
 
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