|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding control to datagridAll columns are bound. In code behind file i use ItemDataBound event to do some formatting of some off the columns. Insted of changing the cell.BackColor = Color.Green; i want to add a checkbox and set it to checked if true and unchecked if not ( in the else loop). Is this possible? Best regards Trond private void dgMessages_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { TableCell cell = e.Item.Cells[7]; long Timediff = long.Parse(cell.Text); if (Timediff == 1 || Timediff == 3 || Timediff == 5 || Timediff == 7 || Timediff == 9 || Timediff==11 || Timediff == 13 ||Timediff == 15 ) { cell.BackColor = Color.Green; cell.Text="OK"; } else { cell.BackColor = Color.Red; cell.Text="-"; } Have a
<asp:TemplateColumn HeaderText="Check"> <ItemTemplate> <asp:CheckBox ID="temp" Runat="server"></asp:CheckBox> </ItemTemplate> </asp:TemplateColumn> in your aspx. in item databound event handler say (assume this check box is at the 1 column) System.Web.UI.WebControls.CheckBox objChck = (System.Web.UI.WebControls.CheckBox)e.Item.Cells[1].FindControl("temp"); Then based on your condition check or uncheck this objChck. Hope this helps!! Ural Show quoteHide quote "Trond" wrote: > I have an ASP.NET page that is displaying data from a dataset in a datagrid. > All columns are bound. In code behind file i use ItemDataBound event to do > some formatting of some off the columns. Insted of changing the > cell.BackColor = Color.Green; i want to add a checkbox and set it to checked > if true and unchecked if not ( in the else loop). Is this possible? > > Best regards > Trond > > private void dgMessages_ItemDataBound_1(object sender, > System.Web.UI.WebControls.DataGridItemEventArgs e) > > { > > try > > { > > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == > > ListItemType.AlternatingItem) > > { > > TableCell cell = e.Item.Cells[7]; > > long Timediff = long.Parse(cell.Text); > > if (Timediff == 1 || Timediff == 3 || Timediff == 5 || Timediff == 7 || > Timediff == 9 || Timediff==11 || Timediff == 13 ||Timediff == 15 ) > > { > > cell.BackColor = Color.Green; > > cell.Text="OK"; > > } > > else > > { > > cell.BackColor = Color.Red; > > cell.Text="-"; > > } > > >
How to get the HtmlForm element of an ASP.NET Page?
CreateUserWizard Control Hidden Controls yield inconsistent behavior on Postbacks Automatic updating an ASPX page Can I set initial focus from server-side into textbox? HOWTO: Bring that row back into focus ... custom webcontrol : render and then get "html" result in server side Listbox and multiple selection Text Length Column span datagrid header |
|||||||||||||||||||||||