I have a rather large gridview (70+ columns) that I'm creating dynamically based on query results. 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. Is that
possible without using the template column?
If possible...can anyone share any links and/or code (VB please)
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?
I've tried running the additional code after the bind:
Dim tccheckcell As New TableCell
Dim checkbox = New CheckBox
tccheckcell.Controls.Add(checkbox)
grdTableDetails.Rows(1).Cells.AddAt(1, tccheckcell)
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)
I ve done this without using template column in aspx page.
But somehow u have to use codebeind to dynamically check box/dropdowns uinsg .cs file have a look
void ITemplate.InstantiateIn(Control container)
{
DropDownList cmd = new DropDownList();
//cmd.AutoPostBack = true;
cmd.ID = "cmd";
//cmd.SelectedItem.Value = "HI";
cmd.Items.Insert(0, "Present");
cmd.Items.Insert(1, "Absent");
cmd.Items.Insert(2, "Week OFF");
cmd.SelectedIndexChanged += 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();
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
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. Plus
with a variety of columns/rows its easier to format them when done dynamically
mr_jay_bee
Member
42 Points
48 Posts
Gridview with dynamically created checkboxes.........
Jun 12, 2012 05:33 PM|LINK
I have a rather large gridview (70+ columns) that I'm creating dynamically based on query results. 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. Is that possible without using the template column?
If possible...can anyone share any links and/or code (VB please)
jbenson001
Member
356 Points
95 Posts
Re: Gridview with dynamically created checkboxes.........
Jun 12, 2012 06:24 PM|LINK
Why is it necessary to NOT use a template column? This is what they are ment for.
mr_jay_bee
Member
42 Points
48 Posts
Re: Gridview with dynamically created checkboxes.........
Jun 13, 2012 05:36 PM|LINK
I've tried using the template column, but I'm still getting funky results. Currently, I'm creating the grid on the fly:
For Each dc In MyDataConnections.m_DAL.DataSet.Tables("table_of_Main_Data").Columns
Dim bfield As New BoundField
bfield.DataField = dc.ColumnName
bfield.HeaderText = dc.ColumnName
grdTableDetails.Columns.Add(bfield)
grdTableDetails.DataSource = MyDataConnections.m_DAL.DataSet.Tables("table_of_Main_Data")
grdTableDetails.DataBind()
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?
I've tried running the additional code after the bind:
Dim tccheckcell As New TableCell
Dim checkbox = New CheckBox
tccheckcell.Controls.Add(checkbox)
grdTableDetails.Rows(1).Cells.AddAt(1, tccheckcell)
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)
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Gridview with dynamically created checkboxes.........
Jun 14, 2012 08:02 AM|LINK
Hi,
Seems you have solved the issue. If so, please share the solution with us.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
shreenidhi
Member
122 Points
76 Posts
Re: Gridview with dynamically created checkboxes.........
Jun 14, 2012 01:26 PM|LINK
Hi,
I ve done this without using template column in aspx page.
But somehow u have to use codebeind to dynamically check box/dropdowns uinsg .cs file have a look
void ITemplate.InstantiateIn(Control container) { DropDownList cmd = new DropDownList(); //cmd.AutoPostBack = true; cmd.ID = "cmd"; //cmd.SelectedItem.Value = "HI"; cmd.Items.Insert(0, "Present"); cmd.Items.Insert(1, "Absent"); cmd.Items.Insert(2, "Week OFF"); cmd.SelectedIndexChanged += 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();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
jbenson001
Member
356 Points
95 Posts
Re: Gridview with dynamically created checkboxes.........
Jun 14, 2012 02:15 PM|LINK
Why do you need to build the grid dynamically?
mr_jay_bee
Member
42 Points
48 Posts
Re: Gridview with dynamically created checkboxes.........
Jun 14, 2012 02:21 PM|LINK
http://stackoverflow.com/questions/4006106/how-to-add-the-checkbox-field-in-gridview
mr_jay_bee
Member
42 Points
48 Posts
Re: Gridview with dynamically created checkboxes.........
Jun 14, 2012 02:24 PM|LINK
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. Plus with a variety of columns/rows its easier to format them when done dynamically