First of all I must say that I am a newbie when it comes to net language.
This is my problem.
How to disabled the asp image button "ImageButton4" when today's date is greater than the registration date in my database ?.
For example the record with date registration '2012-04-14' should not display the asp image button "ImageButton4".
If you have link for similar task, please give it me.
Can you help me? thank you in advance.
Your help would be very appreciated
Thanks for your time and hints.
This is my code:
protected void ImageButton1_Click(object sender, EventArgs e)
{
ImageButton myButton = (ImageButton)sender;
string ID = myButton.CommandArgument.ToString();
Response.Redirect("http://localhost/WebApplication1/default.asp?id=" + ID + "&cks=" + Request.Cookies["MyCookie"].Value + "");
}
ImageUrl="/Images/updateDB.gif" ToolTip="Update DB"
OnClientClick="return confirm('Confirm?.');"
onclick="ImageButton1_Click" />
Chevy Mark SunderlandPosted Apr 17, 2012, 6:16 AM
thank you for your help.
I edit my net code with your suggestions but I have the new error.
I hope your help.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 117: if (dtToday > dtDB)
Line 118: {
Line 119: ImageButton4.Enabled = false;
Line 120: }
Line 121: }
DataKeyNames="ID"
AllowSorting="True"
AllowPaging="True"
PageSize="15"
AutoGenerateColumns="false"
CssClass="first"
OnRowUpdated="GridView1_RowUpdated"
OnRowDataBound="GridView1_RowDataBound">
ImageUrl="/Images/updateDB.gif" ToolTip="Update DB"
OnClientClick="return confirm('Confirm?.');"
onclick="ImageButton1_Click" />
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label Label2 = (Label)e.Row.FindControl("Label2");
ImageButton ImageButton4 = (ImageButton)e.Row.FindControl("ImageButton4");
DateTime dtDB = DateTime.ParseExact(Label2.Text, "dd/MM/yyyy", null);
DateTime dtToday = DateTime.Now;
if (dtToday > dtDB)
{
ImageButton4.Enabled = false;
}
}
}
SenthilkumarPosted Apr 17, 2012, 5:36 AM
You need to bind the data base date into lblDate control.
And also when you find the control,
Chevy Mark SunderlandPosted Apr 17, 2012, 5:29 AM
thank you for your help.
I try your suggestion but I have this error, why? I hope your help.
Compiler Error Message: CS1061: 'System.Web.UI.WebControls.GridViewRow' does not contain a definition for 'Findcontrol' and no extension method 'Findcontrol' accepting a first argument of type 'System.Web.UI.WebControls.GridViewRow' could be found (are you missing a using directive or an assembly reference?)
SenthilkumarPosted Apr 17, 2012, 12:23 AM
Hope this will help you.
Chevy Mark SunderlandPosted Apr 16, 2012, 3:32 PM
ImageButton4 does not exist in current context
public void Page_Load (Object sender, EventArgs e)
{
OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
myConnectionString.Open();
myConnectionString.Dispose();
myConnectionString.Close();
lblMessage.Text = "";
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
if (result < 0) {
ImageButton4.Enable = false;
}
}
ImageUrl="/Images/updateDB.gif" ToolTip="Update DB"
OnClientClick="return confirm('Confirm?.');"
onclick="ImageButton1_Click" />
Abhimanyu K VatsaPosted Apr 16, 2012, 3:14 PM