How can I set the maximum and minimum value for RangeValidator based on two dates
<asp:textbox id=’TextBox1′ runat=’server’></asp:textbox> <asp:rangevalidator id=’RangeValidator1′ type=’Date’ controltovalidate=’TextBox1′ runat=’server’ errormessage=’Not in range’ /> <asp:button id=’Button1′ runat=’server’ text=’Button’></asp:button> VB.NET … Dim dtMinDate As DateTime Dim dtMaxDate As DateTime dtMinDate = Convert.ToDateTime(’04/25/04′) dtMaxDate = Convert.ToDateTime(’10/17/04′) RangeValidator1.MinimumValue = dtMinDate RangeValidator1.MaximumValue = dtMaxDate TextBox1.Text = dtMaxDate.ToShortDateString RangeValidator1.ErrorMessage = ‘Not in Range of ‘ & dtMinDate.ToShortDateString() & ‘ to ‘ & dtMaxDate.ToShortDateString() C# DateTime dtMinDate ; DateTime dtMaxDate ; dtMinDate = Convert.ToDateTime(’04/25/04′); dtMaxDate = Convert.ToDateTime(’10/17/04’); RangeValidator1.MinimumValue = dtMinDate.ToShortDateString () ; RangeValidator1.MaximumValue = dtMaxDate.ToShortDateString () ; TextBox1.Text = dtMaxDate.ToShortDateString(); RangeValidator1.ErrorMessage = ‘Not in Range of ‘ + dtMinDate.ToShortDateString() + ‘ to ‘ + dtMaxDate.ToShortDateString();
How to implement mouseover effects in a <asp:image> web server control
<asp:Image id=’Image1′ runat=’server’ ImageUrl=’b2346.jpg’></asp:Image> VB.NET Image1.Attributes.Add(‘onmouseover’, ‘this.src=’b2456.jpg’’) C# Image1.Attributes.Add(‘onmouseover’, ‘this.src=’b2456.jpg’’);
How to sort the DataGrid using an ArrayList as the DataSource
<asp:DataGrid AllowSorting =True OnSortCommand=’SortData’ id=’DataGrid1′ runat=’server’ EnableViewState=’false’></asp:DataGrid> VB.NET Private Sub Page_Load(sender As Object, e As System.EventArgs) ’ Put user code to initialize the page here Dim arrlist As New ArrayList() arrlist.Add(‘Tips’) arrlist.Add(‘Tricks’) arrlist.Add(‘Code’) arrlist.Add(‘Samples’) DataGrid1.DataSource = arrlist DataGrid1.DataBind() ViewState(‘AList’) = arrlist End Sub ’Page_Load Protected Sub SortData([source] As [Object], e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) If ViewState(‘SortOrder’) Is Nothing Then SortAsc() Else If ViewState(‘SortOrder’).ToString() = ‘ ASC’ Then SortDesc() Else SortAsc() End If End If End Sub ’SortData Sub SortAsc() ViewState(‘SortOrder’) = ‘ ASC’ CType(ViewState(‘AList’), ArrayList).Sort() DataGrid1.DataSource = ViewState(‘AList’) DataGrid1.DataBind() ViewState(‘Sort’) = ‘DESC’ End Sub ’SortAsc Sub SortDesc() ViewState(‘SortOrder’) = ‘ DESC’ CType(ViewState(‘AList’), ArrayList).Sort() CType(ViewState(‘AList’), ArrayList).Reverse() DataGrid1.DataSource = ViewState(‘AList’) DataGrid1.DataBind() ViewState(‘Sort’) = ‘ASC’ End Sub ’SortDesc C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here ArrayList arrlist = new ArrayList (); arrlist.Add (‘Tips’); arrlist.Add (‘Tricks’); arrlist.Add (‘Code’); arrlist.Add (‘Samples’); DataGrid1.DataSource = arrlist ; DataGrid1.DataBind (); ViewState[‘AList’] = arrlist ; } protected void SortData(Object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e ) { if (ViewState[‘SortOrder’] ==null) { SortAsc(); } else if (ViewState[‘SortOrder’].ToString () == ‘ ASC’ ) { SortDesc(); } else { SortAsc(); } } void SortAsc() { ViewState[‘SortOrder’] = ‘ ASC’; ((ArrayList)ViewState[‘AList’]).Sort (); DataGrid1.DataSource = ViewState[‘AList’]; DataGrid1.DataBind (); ViewState[‘Sort’]=’DESC’; } void SortDesc() { ViewState[‘SortOrder’] = ‘ DESC’; ((ArrayList)ViewState[‘AList’]).Sort (); ((ArrayList)ViewState[‘AList’]).Reverse (); DataGrid1.DataSource = ViewState[‘AList’]; DataGrid1.DataBind (); ViewState[‘Sort’]=’ASC’; }
How to sort ArrayList
<asp:Button id=’btnAsc’ runat=’server’ Text=’Asc’></asp:Button> <asp:ListBox id=’ListBox1′ runat=’server’></asp:ListBox> <asp:Button id=’btnDesc’ runat=’server’ Text=’Desc’></asp:Button> VB.NET Private Sub Page_Load(sender As Object, e As System.EventArgs) ’ Put user code to initialize the page here Dim arrlist As New ArrayList() arrlist.Add(‘Tips’) arrlist.Add(‘Tricks’) arrlist.Add(‘Code’) arrlist.Add(‘Samples’) ListBox1.DataSource = arrlist ListBox1.DataBind() ViewState(‘AList’) = arrlist End Sub ’Page_Load Private Sub btnAsc_Click(sender As Object, e As System.EventArgs) CType(ViewState(‘AList’), ArrayList).Sort() ListBox1.DataSource = CType(ViewState(‘AList’), ArrayList) ListBox1.DataBind() End Sub ’btnAsc_Click Private Sub btnDesc_Click(sender As Object, e As System.EventArgs) CType(ViewState(‘AList’), ArrayList).Sort() CType(ViewState(‘AList’), ArrayList).Reverse() ListBox1.DataSource = CType(ViewState(‘AList’), ArrayList) ListBox1.DataBind() End Sub ’btnDesc_Click C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here ArrayList arrlist = new ArrayList (); arrlist.Add (‘Tips’); arrlist.Add (‘Tricks’); arrlist.Add (‘Code’); arrlist.Add (‘Samples’); ListBox1.DataSource =arrlist ; ListBox1.DataBind (); ViewState[‘AList’] = arrlist ; } private void btnAsc_Click(object sender, System.EventArgs e) { ((ArrayList)ViewState[‘AList’]).Sort() ; ListBox1.DataSource =(ArrayList)ViewState[‘AList’] ; ListBox1.DataBind (); } private void btnDesc_Click(object sender, System.EventArgs e) { ((ArrayList)ViewState[‘AList’]).Sort() ; ((ArrayList)ViewState[‘AList’]).Reverse (); ListBox1.DataSource =(ArrayList)ViewState[‘AList’] ; ListBox1.DataBind (); }
I get the error message ‘DataGrid with id ‘DataGrid1′ could not automatically generate any columns from the selected data source’ when I bind a HashTable to the DataGrid
Set the AutoGenerateColumns property of the DataGrid to False.Sample code below VB.NET <asp:DataGrid AutoGenerateColumns=False id=’DataGrid1′ runat=’server’> <Columns > <asp:TemplateColumn HeaderText=’HashTable’> <ItemTemplate> <%# Container.DataItem.Key %> <br> <%# Container.DataItem.Value %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> ’In Page_Load Dim ht As New Hashtable() ht.Add(’emp1′, ‘A’) ht.Add(’emp2′, ‘B’) ht.Add(’emp3′, ‘C’) DataGrid1.DataSource = ht DataGrid1.DataBind() C# <asp:DataGrid AutoGenerateColumns=False id=’DataGrid1′ runat=’server’> <Columns > <asp:TemplateColumn HeaderText=’HashTable’> <ItemTemplate> <%# ((DictionaryEntry)Container.DataItem).Key %><br> <%# ((DictionaryEntry)Container.DataItem).Value %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> //In Page_Load Hashtable ht = new Hashtable(); ht.Add (’emp1′, ‘A’); ht.Add (’emp2′, ‘B’); ht.Add (’emp3′, ‘C’); DataGrid1.DataSource = ht; DataGrid1.DataBind();