|
Why not use a calendar control rather than a textbox? The date will already be formatted.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtTodate"
Format="dd MMM yyyy">
</cc1:CalendarExtender>--%><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtTodate"
ErrorMessage="Invalid Format" ValidationExpression="^((31(?!\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\b|t)t?|Nov)(ember)?)))|((30|29)(?!\ Feb(ruary)?))|(29(?=\ Feb(ruary)?\ (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\b|t)t?|Nov|Dec)(ember)?)\ ((1[6-9]|[2-9]\d)\d{2})$"
ValidationGroup="AddEmp"></asp:RegularExpressionValidator>
Hope this can help you.
|
|
|
|
|
thanks much for you help. Please can you put the code in different format so that I can see it. I can't see all the code.
thanks again.
|
|
|
|
|
|
Hi,
I have a grid which is bound to data coming from a service at runtime.
The issue is every time i select next page number the page goes blank.
My code is as follows: for grid in aspx
<div>
<asp:Label ID="Label1" runat="server" Text="Searching....." Font-Bold = "true"></asp:Label>
<asp:GridView ID="grid1" runat="server" OnPageIndexChanging= "grid1_PageIndexChanged"
AutoGenerateColumns="False" Enabled ="false" AllowPaging="True" PageSize="5">
<Columns>
<asp:BoundField DataField = "Name"/>
<asp:BoundField DataField = "ID"/>
</Columns></asp:GridView>
</div>
the codebehind(.cs) is typically is as follows:
on pageload:
grid1.Enabled = true;
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("ID");
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
grid1.DataSource = dt;
grid1.DataBind();
protected void grid1_PageIndexChanged(Object sender, GridViewPageEventArgs e)
{
grid1.PageIndex = e.NewPageIndex;
grid1.DataBind();
}
what am i missing here
|
|
|
|
|
I think you need to include your Page_Load code inside If( ! PostBack ) { } block.
Please try this.
♫ 99 little bugs in the code,
99 bugs in the code
We fix a bug, compile it again
101 little bugs in the code ♫
|
|
|
|
|
yes my code is inside if (!IsPostBack) block..
but evrytime i click say page 2 the screen goes blank.
|
|
|
|
|
I can't reproduce this behaviour. When paging through the Grid the screen doesn't go blank. Im using VS 2010.
Maybe it has something to do with the data source you've bound to the control?
|
|
|
|
|
my datasource is a list of objects returned from the service.
Since I need to format it before displaying I convert it into a datatable and this datatable is datasource to the grid. I have stepped thru and found that datatable has populated fine with all the values. even the page comes up fine with all the data and 123 page links down. it's when i click page 2/3 link in pager that it goes blank. am using vs 2008 .net 3.5
|
|
|
|
|
You should probably separate all the three subroutines. Have the !(PagePostback), datagrid itself, and the Grid1_PageIndexChanging all separate and not in one sub.
|
|
|
|
|
my page load checks if it's not postback it calls the gridview load which does what i've posted and i have seperate event handler.
|
|
|
|
|
I had the same issue. I had to literally re-bind the entire datagrid for it to work. It worked for me, and was working under time cruch, I stuck with it.
|
|
|
|
|
what do u mean by rebind, rewrite the code?
|
|
|
|
|
Hi ,
Your Page_Load checks if it is not a postback right ?
This means your code sets the DataSource property of your grid ONLY once and that is when the page loads for the first time.
Please write the code "grid.DataSource = dataTable;" just before the code "grid.DataBind()" and let me know if it works.
Always make it a habit to set the DataSource of a grid just before calling the DataBind() method on the grid.
E.g. I would always code method like "BindPersonsData()" in my application which would be like -
private void BindPersonsData()
{
grdPersons.DataSource = GetPersons();
grdPersons.DataBind();
}
private DataTable GetPersons()
{
DataTable dt = new DataTable();
//logic to get data
return dt;
}
-------------
Ankur - The Tech Anky
Think Simple, Code Simple, Do Big
|
|
|
|
|
copy this aspx.cs page
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BIndgrid();
}
}
void BIndgrid()
{
grid1.Enabled = true;
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("ID");
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
dt.Rows.Add("Jack", 1);
dt.Rows.Add("Jill", 2);
grid1.DataSource = dt;
grid1.DataBind();
}
protected void grid1_PageIndexChanged(Object sender, GridViewPageEventArgs e)
{
grid1.PageIndex = e.NewPageIndex;
grid1.DataBind();
BIndgrid();
}
}
|
|
|
|
|
Super.
Thanks Sneha Bisht
|
|
|
|
|
Hi,
how I can get the birthday from column in database ( as datetime type ) and display it in a separate dropdownlist one for day and other for month and textbox for year .
I want get the information to update on it .
thanks .
|
|
|
|
|
Is it stored in the database as a DateTime? If so then you get the same way you would get any other column. Once you have the DateTime object you use the properties the structure, Day, Month, Year to get the constituent parts.
In these situations I usually rely on a little trick I like to refer to as Reading the Documentation, or as some abbreviate it, RTFM
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Why you aren't using Calendar1 control?
If you have to split birthday value in controls then use Year,Month,Day SQL Functions.
e.g
select year(birthday) from mytable
select month(birthday) from mytable
select day(birthday) from mytable
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
no I don't need to use the calender but I need only return birthdate from database into variable as DateTime and then spilt it into day to put it in the dropdownlist , month into another dropdownlist , year into textbox to update information about user .
|
|
|
|
|
So, you can bind dropdowlists and textbox with query which I wrote you in previous post.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
So you want to use three query, with all the overhead, to return one value, DateTime, which already has the properties for Day, Month, Year. Even if you combined into one query it is still unnecessary to separate the values in the SQL statement.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
That was only example about Year,Month,Day SQL functions.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
how I can get the birthday from column in database ( as datetime type ) and display it in a separate dropdownlist one for day and other for month and textbox for year .
I want get the information to update on it .
for that task
first you have to create two dropdownlist for day and month and fill them.
then try this code
void BIndBirthDay()
{
DateTime _bdate = DateTime.Now; -- get this date from database field
int day = _bdate.Day; -- return int value(find day of datetime field like that)
drp_day.SelectedIndex = -1;
drp_day.Items.FindByValue(Convert.ToString(day)).Selected = true; -- bind that perticulare day to dropdownlist by that
}
hope this helps and also same down for month (_bdate.Day) and year (_bdate.Year)
|
|
|
|
|
Yes, that's really what I want
thank you very much
|
|
|
|