How can we add a check box or a dropdown list to a column in a datagrid?

Post your answer

Showing Answers 1 - 15 of 15 Answers

vinod arya

  • Sep 17th, 2005
 

you can use vaspread, a 3rd party tool

  Was this answer useful?  Yes

Shobha

  • Sep 20th, 2005
 

By using template column, as

<asp:TemplateColumn>

<asp:ItemTemplate>

<asp:CheckBox></asp:CheckBox>

<asp:DropDownList></asp:DropDownList>

</asp:ItemTemplate>

</asp:TemplateColumn>

  Was this answer useful?  Yes

Mahendra Raja

  • Sep 21st, 2005
 

If u want to add a check box in a Datagrid in Asp.Net applications. U select the datagrid in the webform and at bottom of properties window u r able to view property builder (Click it), then a dialog window will be opened. there u select columns and then in the column box select template column. the type a name for that column. click apply then close that window. now (right click) the datagrid and select edit template, there select the column name displayed bcoz it will display only the template column. then entire datagrid appearance will be changed. Now in the datagrid click the item template using mouse. the cursor blibks in that column. Go to the tool box double click any one of the control like(Check-Box). now it will be added to the item template. then right click the datagrid and (click) End Template Editing.now u will be getting the grid to original appearance with Checkbox in the template column.

  Was this answer useful?  Yes

Nithin

  • Sep 26th, 2005
 

Add a template column to the datagrid and select the Checkbox or DropdownList for the ItemTemplate

  Was this answer useful?  Yes

Rameez Mohammed

  • Sep 29th, 2005
 

just make the column where u want to put the combo box a Template Column.Then right click the grid,go to--> edit template-->column name.Delete the text box in the field.place the drop down there.in code(VB)get the control as ctype(datagridname.findcontrol("ddl1"),dropdownlist).text.trim to get the value of the ddl.

  Was this answer useful?  Yes

Saira

  • Oct 10th, 2005
 

By making use of a template column for the datagrid and then droping a checkbox or dropdownlist on it.Finally binding it with the datasource.

  Was this answer useful?  Yes

Ketan

  • Oct 14th, 2005
 

Hello dr.,

 With the help of template command coloumn we can add all types of webserver control in datagrid.

Thanks,

With regards,

 Ketan Pathak

  Was this answer useful?  Yes

entm

  • Nov 2nd, 2005
 

Here's a programatic example:

 
<asp:TemplateColumn HeaderText="myColumn" ItemStyle-Wrap="False">
          <ItemTemplate>
           <asp:DropDownList ID="dropList1" Runat=server DataTextField="myText" DataValueField="table_identifier" DataSource='<%# GetSrc()%>' SelectedIndex='<%# GetSelIndex(Container.DataItem("myColumn"))%>' Enabled='<%# GetBool("myColumn")%>' OnSelectedIndexChanged="GetSelChanged" AutoPostBack=True/>
          </ItemTemplate>


Define this at the top of your code:

Dim ds As DataSet = New DataSet

Function GetSrc() As DataSet

cnstr = ConfigurationSettings.AppSettings("myDBConnString")

dropList1.Clear()

Dim cn As New SqlConnection(cnstr)

sql = "SELECT table_identifier, mytext FROM myTable"


Dim
da As SqlDataAdapter

da = New SqlDataAdapter(sql, cn)

' fill dataset
cn.Open()
da.Fill(ds, "myTable")
cn.Close()

' Add null row to dataset.
Dim dt As DataTable = ds.Tables("myTable")

Dim NullRow As DataRow = dt.NewRow()
NullRow("table_identifier") = "0"
NullRow("myText") = "Select Something Here"
dt.Rows.InsertAt(NullRow, 0)

Return ds

End Function

Function GetSelIndex(ByVal iVal As Object) As Integer

' loop through dataset

Dim sVal As String = iVal.ToString
Dim iLoop As Integer
Dim dt As DataTable
dt = ds.Tables("myTable")

For iLoop = 0 To dt.Rows.Count - 1

If sVal = dt.Rows(iLoop)("table_identifier").ToString Then

  Return iLoop

End If

Next iLoop

End Function

 

Function GetBool()
' This function would contain code allowing you to disable the control if the user/entity did not have proper rights to use this control in the grid or change it.

End Function

  Was this answer useful?  Yes

Leigh Anne

  • Apr 13th, 2006
 

Ok, I think Eric Moore's post may have been what I'm looking for, but I'm a total novice and need help understanding the code. I have added a template column to my data grid to hold a column of checkboxes. I cannot figure out, though, how to use the click event procedure to make the system recognize when the boxes are checked. Basically, I have a data grid representing the courses a college student is currently enrolled in. There is a column called "Drop" which is my template column that holds checkboxes. I want to allow the student to check mark the box(es) and hit a submit button. Then, I want the info from those boxes emailed to a particular person. My main problem right now is getting the code to recognize when the box is checked. Could someone help me in very basic terms?? :) Thanks so much!

  Was this answer useful?  Yes

ali1dc

  • Dec 16th, 2008
 

you can use the same thing for different control:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">

  <Columns>

    <asp:BoundField DataField="" HeaderText="FirstName"/>

    <asp:BoundField DataField="" HeaderText="LastName" />

    <asp:TemplateField HeaderText="Gender">

      <ItemTemplate>

        <asp:DropDownList ID="mytext" runat="server"></asp:DropDownList>

      </ItemTemplate>

    </asp:TemplateField>

  </Columns>

</asp:GridView>

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions