Why am I getting an ‘AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID MyDataGrid when AllowPaging is set to true and the selected datasource does not implement ICollection’ Error?
You are probably trying to implement paging in a DataGrid while binding the DataGrid with a DataReader. To fix this, instead of using a DataReader use a DataSet
How do I conditionally set the text color of a cell in my Datagrid based on the cell’s/fields’s value?
In the ItemDataBound event you can access the Cells() collection of the current Datagrid item (or row) and set it’s ForeColor. <asp:DataGrid OnItemDataBound='ItemDB' id='DataGrid1' runat='server'></asp:DataGrid> VB.NET protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) If (e.Item.ItemType = ListItemType.Item Or _ e.Item.ItemType = ListItemType.AlternatingItem) Then If e.Item.DataItem(6) > 15 Then e.Item.Cells(6).ForeColor = System.Drawing.Color.Green Else e.Item.Cells(6).ForeColor = System.Drawing.Color.Red End If End If End Sub C# protected void ItemDB(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if((e.Item.ItemType ==ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem) ) { if (Convert.ToInt16 (e.Item.Cells[6].Text) >15 ) { e.Item.Cells[6].ForeColor = System.Drawing.Color.Green; } else { e.Item.Cells[6].ForeColor = System.Drawing.Color.Red; } } } In Cells[x]/Cells(x) x=> index number to the list of fields in the row.
How to open a new window with multiple parameters when clicked on a hyperlink in a column in a datagrid
The column should be defined as a TemplateColumn as follows and the NavigateUrl for that hyperlink can be set as follows to open a new window with parameters varying based on the row in which the hyperlink is present. <asp:TemplateColumn > <ItemTemplate> <asp:Hyperlink ID='Hyperlink2' Runat='Server' NavigateUrl= <%#'javascript:my_window=window.open(’webform2.aspx?id=' + DataBinder.Eval(Container.DataItem,'productid').ToString() + '&Supplierid=' + DataBinder.Eval(Container.DataItem,'SupplierID').ToString() + '’,’my_window’,’width=300,height=300’);my_window.focus()' %> text=<%#DataBinder.Eval(Container.DataItem,'ProductName').ToString() %>> </asp:Hyperlink> </ItemTemplate> </asp:TemplateColumn> The above approach would avoid the problem of showing the screen of [Object] on the parent page
Why do I get error message ‘The control ‘_ctl1’ of type ‘TextBox’ must be inside a form label with runat=server’ while trying to place a control inside a form dynamically
You are probably adding the textbox into the Page directly instead of adding it to the Page’s form. Try doing this: VB.NET Me.Page.Controls(1).Controls.Add(txtboxctrl) C# this.Page.Controls[1].Controls.Add(txtboxctrl);
What is the difference between User Controls and Custom Controls?
User Controls are text files with the extension ’.ascx’ which enables you to make GUI re-usable controls. Its a text file, which contains a mixture of HTML and scripting. User Controls can be edited in an editor. On the other hand Custom Controls reside in compiled ( Dll ) assemblies. They are non-GUI but can emit HTML GUI at runtime. Example of Custom Controls would be the sever controls which come bundled with the .NET SDK like DataGrid, Repeater, DataList etc. Custom Controls are always compiled into Dll’s and hence require good programming knowledge. The purpose of Custom Controls is also to create re-usable units of code.