D
duff
Hiya,
I'm trying to replace the commented out code below with a neater
version using the IAttributeAccessor interface (so that I don't have to
write 'if' statements for all control types).
At the moment this doen't work. The test line I put in
(string s = ControlAttributes.string s = ControlAttributes.GetAttribute
("Text");
is giving me s as null. Neither the GetAttribute nor the SetAttrubute
fail - they just don't seem to do anything.
Any clues what I'm doing wrong?
Kirsty
___________________________________
public void SetCaptions
(
System.Web.UI.HtmlControls.HtmlForm WebForm,
System.Data.DataSet Captions
)
{
System.Data.DataTable CaptionDataTable = new System.Data.DataTable();
string ControlName = "";
string ControlText = "";
System.Web.UI.Control Control;
// Get the captions data table from the dataset
CaptionDataTable = Captions.Tables[_CaptionDataTableName];
// Go through the data, setting the Text property of each control
foreach (System.Data.DataRow Row in CaptionDataTable.Rows)
{
ControlName = Row[_ControlNameFieldName].ToString();
ControlText = Row[_ControlCaptionFieldName].ToString();
Control = WebForm.FindControl (ControlName);
if (!(Control == null))
{
System.Web.UI.IAttributeAccessor ControlAttributes =
(System.Web.UI.IAttributeAccessor)Control;
string s = ControlAttributes.GetAttribute ("Text");
ControlAttributes.SetAttribute ("Text",ControlText);
// if (Control is System.Web.UI.WebControls.Label)
// {
// System.Web.UI.WebControls.Label Lbl =
(System.Web.UI.WebControls.Label)Control;
// Lbl.Text = ControlText;
// } // (ControlType is System.Web.UI.WebControls.Label)
} //(!(Control ==null))
} //foreach
} //SetCaptions
I'm trying to replace the commented out code below with a neater
version using the IAttributeAccessor interface (so that I don't have to
write 'if' statements for all control types).
At the moment this doen't work. The test line I put in
(string s = ControlAttributes.string s = ControlAttributes.GetAttribute
("Text");
is giving me s as null. Neither the GetAttribute nor the SetAttrubute
fail - they just don't seem to do anything.
Any clues what I'm doing wrong?
Kirsty
___________________________________
public void SetCaptions
(
System.Web.UI.HtmlControls.HtmlForm WebForm,
System.Data.DataSet Captions
)
{
System.Data.DataTable CaptionDataTable = new System.Data.DataTable();
string ControlName = "";
string ControlText = "";
System.Web.UI.Control Control;
// Get the captions data table from the dataset
CaptionDataTable = Captions.Tables[_CaptionDataTableName];
// Go through the data, setting the Text property of each control
foreach (System.Data.DataRow Row in CaptionDataTable.Rows)
{
ControlName = Row[_ControlNameFieldName].ToString();
ControlText = Row[_ControlCaptionFieldName].ToString();
Control = WebForm.FindControl (ControlName);
if (!(Control == null))
{
System.Web.UI.IAttributeAccessor ControlAttributes =
(System.Web.UI.IAttributeAccessor)Control;
string s = ControlAttributes.GetAttribute ("Text");
ControlAttributes.SetAttribute ("Text",ControlText);
// if (Control is System.Web.UI.WebControls.Label)
// {
// System.Web.UI.WebControls.Label Lbl =
(System.Web.UI.WebControls.Label)Control;
// Lbl.Text = ControlText;
// } // (ControlType is System.Web.UI.WebControls.Label)
} //(!(Control ==null))
} //foreach
} //SetCaptions