I have a DataGrid displaying values from a database. The DataGrid is then populated in a different class file. But I have a checkbox in the html code checking if it is checked or not. When the checkbox is checked I want to load the RevToDate column from the DataGrid. So I'm getting an error: chkRevToDate does not exist. So how do I call the chkRevToDate checkbox in a different class?
Code for DataGrid in a file called Customer.aspx.cs:
<div runat="server" id="dvMainGrid" class="dvResultsLookup">
<asp:DataGrid runat="server" CssClass="tblResults" OnItemDataBound="dgList_ItemCreated" AllowSorting="true" OnSortCommand="dgCustomer_Sort" ID="dgCustomers" DataKeyField="ID" AutoGenerateColumns="false">
<HeaderStyle CssClass="tblResultsHeader" />
<AlternatingItemStyle BackColor="#EEEEEE" />
<Columns>
<asp:HyperLinkColumn ItemStyle-CssClass="loading" DataNavigateUrlFormatString="Customer.aspx?CustID={0}" DataNavigateUrlField="ID" DataTextField="AccountCode" HeaderText="A/C Code" SortExpression="AccountCode"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="VATNo" HeaderText="VAT No" SortExpression="VATNo"></asp:BoundColumn>
<asp:BoundColumn DataField="CurrencyDesc" HeaderText="Currency" SortExpression="CurrencyDesc"></asp:BoundColumn>
<asp:BoundColumn DataField="RevToDate" HeaderText="Rev To Date (Net)" Visible="false" SortExpression="RevToDate"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
And in the same class as the DataGrid I have the code for the checkbox
<asp:CheckBox runat="server" ID="chkRevToDate" Checked="false" />
Code for loading values into DataGrid in a file called Customer.cs:
public static DataGrid BuildGrid(bool IncludeContacts)
{
DataGrid NewDg = new DataGrid();
NewDg.DataKeyField = "ID";
NewDg.AutoGenerateColumns = false;
NewDg.CssClass = "tblResults draggable";
NewDg.HeaderStyle.CssClass = "tblResultsHeader";
NewDg.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
NewDg.ItemStyle.CssClass = "ResultsStyle";
NewDg.Columns.Add(Load.CreateBoundColumn("VATNo", "VAT No"));
NewDg.Columns.Add(Load.CreateBoundColumn("CurrencyDesc", "Currency"));
if (chkRevToDate.Checked) //error
{
NewDg.Columns.Add(Load.CreateBoundColumn("RevToDate", "Re To Date (Net)"));
}
return NewDg;
}
Is there a way to call chkRevToDate in a different class?
Aucun commentaire:
Enregistrer un commentaire