elenabukvp
New Member
2 Questions:<BR><BR>1) How do I specify the width of a BoundColumn in a DataGrid?<BR><BR>2) I want to change the font color of a row in a datagrid depending on the values of one of the columns. eg: Phase column, Phase 1 - row font is red, phase 2 - row font is green, phase 3 - row font is blue.<BR><BR>ThanksUse the ItemStyle Width tag in your bound column definition:<BR><BR><ASP:BoundColumn<BR> HeaderText = "Date" <BR> DataField = "rDate"<BR> DataFormatString = "{0:d}"<BR> SortExpression = "rDate" ><BR> <ItemStyle Width = "60" /><BR></ASP:BoundColumn><BR>... thanks. You could also do it like this:<BR><BR><ASP:BoundColumn <BR> HeaderText = "Date" <BR> DataField = "rDate" <BR> DataFormatString = "{0:d}" <BR> SortExpression = "rDate" <BR> ItemStyle-Width = "60" /><BR>Hook into the ItemDataBound event, here's a simple demo:<BR><BR>http://www.flws.com.au/showusyourcode/codeLib/code/NET_DataBind.asp?catID=5Thanks, heres my solution:<BR><BR><script><BR>....<BR>Sub fn_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)<BR> <BR> ' If the current item is not a Header or Footer item<BR> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then<BR><BR> ' if TaskComplete = 1 then change the font colour to blue<BR> If e.Item.Cells(4).Text.ToString() = "1" Then<BR> <BR> ' color the Row Font a different color<BR> e.Item.ForeColor = System.Drawing.Color.FromName("Blue")<BR> <BR> End If<BR><BR> ' if TaskCurrent = 1 then change the font colour to green<BR> If e.Item.Cells(5).Text.ToString() = "1" Then<BR> <BR> ' color the Row Font a different color<BR> e.Item.ForeColor = System.Drawing.Color.FromName("Green")<BR> <BR> End If<BR> <BR> ' if TaskOver = 1 then change the font colour to red<BR> If e.Item.Cells(6).Text.ToString() = "1" Then<BR> <BR> ' color the Row Font a different color<BR> e.Item.ForeColor = System.Drawing.Color.FromName("Red")<BR> <BR> End If<BR> <BR> End If<BR><BR>End Sub<BR>...<BR></script><BR>...<BR><ASP
ataGrid <BR> id="MyDataGrid" <BR> runat="server" <BR> Width="85%" <BR> BackColor="#ccccff" <BR> BorderColor="black" <BR> ShowFooter="false" <BR> CellPadding="3" <BR> CellSpacing="0" <BR> Font-Name="Verdana" <BR> Font-Size="8pt" <BR> HeaderStyle-BackColor="#aaaadd" <BR> HeaderStyle-Font-Size="10pt" <BR> HeaderStyle-Font-Bold="True" <BR> MaintainState="false" <BR> OnItemDataBound="fn_ItemDataBound"<BR> AutoGenerateColumns="False"><BR> <BR> <AlternatingItemStyle BackColor="White" /><BR> <Columns><BR> <asp:HyperLinkColumn HeaderText="Task" DataNavigateUrlField="TaskID" DataNavigateUrlFormatString="comment.aspx?TaskID={0}" DataTextField="TaskName" DataTextFormatString="{0:c}" ItemStyle-Width="20%" /><BR> <asp:BoundColumn HeaderText="Description" DataField="Descript" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="60%" /><BR> <asp:BoundColumn HeaderText="Estimated Completion Date" DataField="ECompDate" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10%" DataFormatString="{0:dd-MM-yyyy}" /><BR> <asp:BoundColumn HeaderText="Completion Date" DataField="CompDate" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10%" DataFormatString="{0:dd-MM-yyyy}" /><BR> <asp:BoundColumn DataField="TaskComplete" Visible="False" /><BR> <asp:BoundColumn DataField="TaskCurrent" Visible="False" /><BR> <asp:BoundColumn DataField="TaskOver" Visible="False" /><BR> </Columns><BR> </ASP
ataGrid><BR>

