Gridview with dynamically created checkboxes.........http://forums.asp.net/t/1813464.aspx/1?Gridview+with+dynamically+created+checkboxes+Thu, 14 Jun 2012 14:24:32 -040018134645022564http://forums.asp.net/p/1813464/5022564.aspx/1?Gridview+with+dynamically+created+checkboxes+Gridview with dynamically created checkboxes......... <p>I have a rather large gridview (70&#43; columns) that I'm creating dynamically based on query results. &nbsp;Without using a template column, I would like to create a check box for each row of data so that a user may select one or multiple rows of data. &nbsp;Is that possible without using the template column?</p> <p></p> <p>If possible...can anyone share any links and/or code (VB please)</p> 2012-06-12T17:33:01-04:005022613http://forums.asp.net/p/1813464/5022613.aspx/1?Re+Gridview+with+dynamically+created+checkboxes+Re: Gridview with dynamically created checkboxes......... <p>Why is it necessary to NOT use a template column? &nbsp;This is what they are ment for.</p> 2012-06-12T18:24:15-04:005024459http://forums.asp.net/p/1813464/5024459.aspx/1?Re+Gridview+with+dynamically+created+checkboxes+Re: Gridview with dynamically created checkboxes......... <p>I've tried using the template column, but I'm still getting funky results. &nbsp;Currently, I'm creating the grid on the fly:</p> <p>For Each dc In MyDataConnections.m_DAL.DataSet.Tables(&quot;table_of_Main_Data&quot;).Columns<br> Dim bfield As New BoundField</p> <p>bfield.DataField = dc.ColumnName<br> bfield.HeaderText = dc.ColumnName</p> <p>grdTableDetails.Columns.Add(bfield)</p> <p>grdTableDetails.DataSource = MyDataConnections.m_DAL.DataSet.Tables(&quot;table_of_Main_Data&quot;)<br> grdTableDetails.DataBind()</p> <p>This code works and I bind my data....my grid shows up.....I see a spot for the checkbox (eg...an additional column at pos(1), but there is no checkbox in said column? &nbsp;</p> <p></p> <p>I've tried running the additional code after the bind:</p> <p>Dim tccheckcell As New TableCell<br> Dim checkbox = New CheckBox<br> tccheckcell.Controls.Add(checkbox)<br> grdTableDetails.Rows(1).Cells.AddAt(1, tccheckcell)</p> <p></p> <p>which makes the checkbox show up, but it offsets all of my data to the right (eg...headers stay in the same position, but the row data moves over one space)</p> <p></p> 2012-06-13T17:36:28-04:005025299http://forums.asp.net/p/1813464/5025299.aspx/1?Re+Gridview+with+dynamically+created+checkboxes+Re: Gridview with dynamically created checkboxes......... <p>Hi,</p> <p>Seems you have solved the issue. If so, please share the solution with us.</p> <p>Thanks,</p> 2012-06-14T08:02:37-04:005025945http://forums.asp.net/p/1813464/5025945.aspx/1?Re+Gridview+with+dynamically+created+checkboxes+Re: Gridview with dynamically created checkboxes......... <p>Hi,</p> <p>I ve done this without using template column in aspx page.</p> <p>But somehow u have to use codebeind to dynamically check box/dropdowns uinsg .cs file have a look</p> <pre class="prettyprint">void ITemplate.InstantiateIn(Control container) { DropDownList cmd = new DropDownList(); //cmd.AutoPostBack = true; cmd.ID = &quot;cmd&quot;; //cmd.SelectedItem.Value = &quot;HI&quot;; cmd.Items.Insert(0, &quot;Present&quot;); cmd.Items.Insert(1, &quot;Absent&quot;); cmd.Items.Insert(2, &quot;Week OFF&quot;); cmd.SelectedIndexChanged &#43;= new EventHandler(Dynamic_Method); container.Controls.Add(cmd); } protected void Dynamic_Method(object sender, EventArgs e) { value = (DropDownList)sender).SelectedItem.Value;//u can use checkbox as well } TemplateField TmpCol = new TemplateField(); TmpCol.HeaderText = dls[i].ToString(); gv.Columns.Add(TmpCol); TmpCol.ItemTemplate = new TemplateHandler();</pre> <p>You can use the checkbox to achive the same.. Its bit tedious and time consuming but still u can achive. You would not find so many blogs answering this as this requirement is complex and needs observation by techy</p> 2012-06-14T13:26:51-04:005026049http://forums.asp.net/p/1813464/5026049.aspx/1?Re+Gridview+with+dynamically+created+checkboxes+Re: Gridview with dynamically created checkboxes......... <p>Why do you need to build the grid dynamically?</p> 2012-06-14T14:15:36-04:005026060http://forums.asp.net/p/1813464/5026060.aspx/1?Re+Gridview+with+dynamically+created+checkboxes+Re: Gridview with dynamically created checkboxes......... <p><span>http://stackoverflow.com/questions/4006106/how-to-add-the-checkbox-field-in-gridview</span></p> 2012-06-14T14:21:35-04:005026068http://forums.asp.net/p/1813464/5026068.aspx/1?Re+Gridview+with+dynamically+created+checkboxes+Re: Gridview with dynamically created checkboxes......... <p>I have multiple datatables feeding the one grid.......some tables return more columns/rows than the other (depends on what the user is looking for).....didn't want to get tied down creating boundfields dynamically or creating template based grids. &nbsp;Plus with a variety of columns/rows its easier to format them when done dynamically</p> 2012-06-14T14:24:32-04:00