Hi Steve:
Sorry about my poor description. I post simplified version of code here.
I have a customized control MyControl like
public class MyControl : WebControl
{
private int nMyControlID;
private string strImagePath;
public int MyControlID
{
get
{
return nMyControlID;
}
set
{
nMyControlID = value;
}
}
public string ImagePath
{
get
{
return strImagePath;
}
set
{
strImagePath = value;
}
}
protected override void Render(HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddAttribute("src", ResolveUrl(ImagePath);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag(); //img
writer.RenderEndTag(); //div
writer.RenderEndTag(); //a
}
}
And In my code I have
List<MyControllstResult = new List<MyControl>();
Database db = DatabaseFactory.CreateDatabase("MyDB");
string sqlCommand = "dbo.usp_GetAllImageList";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
using (DataSet ds = db.ExecuteDataSet(dbCommand))
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
DataRowRecord drMyControl = new DataRowRecord(dr);
MyControl obj = new MyControl();
obj.MyControlID = DataUtil.GetIntValue(drMyControl,
"MyControlID");
obj.ImagePath = DataUtil.GetStringValue(drMyControl, "ImagePath");
lstResult.Add(obj);
}
}
then I databind my list with the datalist like
datalist.datasource = lstResult;
datalist.databind():
the problem I have now is the datalist do create four customized controls.
but images do not display at all. I think the value is not bound to the
control.How can I solve this problem. Do I need to create another customized
databound list control for mycontrol?
Thanks a lot
Regards
Victor
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:VK**************@TK2MSFTNGHUB02.phx.gbl...
Hi Victor,
Based on your description, what you want is display a custom control in a
DataList control's template(in each row after databind), correct?
For the "MyControl" you mentioned, is it a custom webserver control or web
usercontrol(ascx)? As you said that after you perform databindin on the
DataList, the images are not displayed as expected, do you mean your
custom
webcontrol(MyControl) will display an Image if working correctly? Also, I
saw you bind the DataList to a List<of MyControl type, is this just a
test datasource? Generally, you should bind DataList or other template
databound control to a DataSource object (such as DataReader, DataSet or
other custom data object Array/List). If convenient, you can also provide
the complete code snippet (or simplified one of your custom control) so
that we can get a clear view on it.
If there is anything I missed, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.