Datagrid & checkbox column

E

et

All the articles on checkboxes in a datagrid revolve around using the
checkboxes for user selection.

I need to have a checkbox inserted and its value based on a the dataset the
grid is bound to. How do I retrieve that value?

This is my datagrid:
<asp:datagrid id=dg runat="server" AutoGenerateColumns="False"
CellPadding="3" BackColor="White" BorderColor="#999999" BorderWidth="1px"
GridLines="Vertical" BorderStyle="None" >
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn Visible="False" DataField="ID"
ReadOnly="True"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="FeePaid">
<ItemTemplate>
<%#Container.DataItem("FeePaid")%>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox runat="server" ID="chkFeePaid"/>
</EditItemTemplate>
</asp:TemplateColumn>
</asp:datagrid

I don't know what to put in the code to get the checkbox, upon editing the
row, to get the value of the cell, then check or uncheck the checkbox
accordingly. I would also need to update the dataset and database with the
new value.
 
U

user

et said:
I need to have a checkbox inserted and its value based on a the dataset the
grid is bound to. How do I retrieve that value?

Hi et,
I had some code to do just that - I'm sure you can figure it out, but if you
need clarification let me know.

private void dgdRegions_ItemCreated(
object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drvTemp = (DataRowView)e.Item.DataItem;
CheckBox chkCreate = (CheckBox)e.Item.FindControl("chkTemp");
chkCreate.Checked = bool.Parse(drvTemp["contract"].ToString());
}
}

I have a little datagrid demo with checkboxes, paging and dropdowns on my
website. You can download it from http://mamakin1976.plus.com/download.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top