Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

int type causes error

Status
Not open for further replies.

JohnB33

Programmer
Aug 23, 2022
1
GB
Hi,
I have this code which causes an error.




// Edit

if (e.CommandName == "Edit")

{

// Get the item

RepeaterItem Item = ((RepeaterItem)((Button)e.CommandSource).NamingContainer);



// Get buttons and repeater

Button savebtn = (Button)(Item.FindControl("btnSave"));

Button editbtn = (Button)(Item.FindControl("btnEdit"));

Repeater rFields = (Repeater)(Item.FindControl("repFields"));


// Store markers

((HiddenField)Item.FindControl("prevEnabled")).Value = btnPreviousRec.Enabled ? "1" : "0";

((HiddenField)Item.FindControl("nextEnabled")).Value = btnNextRec.Enabled ? "1" : "0";



// Enable my fields

foreach (RepeaterItem RI in rFields.Items)

{

// Get data type

HiddenField dt = (HiddenField)(RI.FindControl("hdnDBDataType"));



// Set controls

if (RI.FindControl("chkSetting").Visible) ((CheckBox)RI.FindControl("chkSetting")).Enabled = true;

if (RI.FindControl("ddlSetting").Visible) ((DropDownList)RI.FindControl("ddlSetting")).Enabled = true;

if (RI.FindControl("txtSetting").Visible)

{

((TextBox)RI.FindControl("txtSetting")).Enabled = true;


// Check my data type

if (dt.Value.ToLower().Substring(0, 4).Equals("date")) ((CalendarExtender)RI.FindControl("extDateTime")).Enabled = true;

}

}

}


This is the line which causes the erro:
dt.Value.ToLower().Substring(0, 4).Equals("date")
It works fine if dt.Value different to int, e.g. "varchar" or "datetime"
Is this a good fix ?
if(dt.Value != "int" && dt.Value.ToLower().Substring(0, 4).Equals("date"))
TIA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top