(e.g. to set rowcolor based on a hidden value)
if you have a gridview that has hidden cells like
<asp:GridView ID="Timeevents" runat="server" OnRowDataBound="Timeevents_RowDataBound" OnRowCommand = "Timeevents_RowCommand" AutoGenerateColumns="False"> <columns> <asp:BoundField DataField="CaseID" HeaderText="CaseID" Visible = "False" /> <asp:BoundField DataField="caseworkerID" HeaderText="CwID" Visible = "False" /> <asp:BoundField DataField="EventTypeID" HeaderText="EvTypeID" Visible = "False" /> <asp:BoundField DataField="CaseWorker" HeaderText="Case Worker" /> <asp:BoundField DataField="EventDate" HeaderText="Event Date" /> <asp:BoundField DataField="Code" HeaderText="Code" /> <asp:BoundField DataField="TotalUnits" HeaderText="Total Units" /> <asp:BoundField DataField="EventType" HeaderText="Event Type" /> <asp:BoundField DataField="UnitCost" HeaderText="Unit Cost" /> <asp:BoundField DataField="TotalCost" HeaderText="Total Cost"/> <asp:TemplateField HeaderText="ADD"> <ItemTemplate> <asp:Button ID="AddUnit" runat="server" Text=" +1 " CommandName="AddUnit" CommandArgument='<%# Eval("CaseID")+ ";" + Eval("CaseworkerID")+ ";" + Eval("EventDate")+ ";" + Eval("EventTypeID")+ ";" + ("1")%>'/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
then it turns out to be impossible to get these values in the onRowDatabound handler using (e.Row.Cells [2] .Text)
I circumvented this problem by not setting any of the BoundFields to Visible = "False" so by default they are visible = "true". getting the values that I need in the onRowDatabound handler in the code behind, and then making them invisible afterwards. like this.
protected void Timeevents_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) {
was pretty green, it took me many times to go into many forums and debug it to understand that the handler did not see the hidden data binding fields, and I did not seem to find an answer to the question of how to set rowcolour based on the hidden field, so I although id just posted it for others to find
If any experts know a better or alternative way, perhaps they can also add cheers code / comments!
source share