Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Customized Control in the Datalist doesnt render

Reply
Thread Tools

Customized Control in the Datalist doesnt render

 
 
Victor
Guest
Posts: n/a
 
      07-04-2007
Hi. all
I have a customize web control. I have three simple properties and
customized render class. then I add this control into my datalist like
<aspataList ID="datalist" runat="server" RepeatColumns="3">
<ItemTemplate>
<uc:mycontrol id="test" runat="server" />
</ItemTemplate>
</aspataList>
In the code-behind I have something like
List<mycontrol > lst = new List<mycontrol >;
lst.add(new mycontrol ());
lst.add(new mycontrol ());
lst.add(new mycontrol ());
datalist.datasource= lst;
datalist.databound();

But i found the control can not be rendered properly. Instead of displaying
four images, no images has been shown. What did I do wrong here? Can someone
give me some reference on how to add your customized control to datalist
then bind the value and render it properly.

Cheers
Thanks a lot
Victor






 
Reply With Quote
 
 
 
 
Masudur
Guest
Posts: n/a
 
      07-04-2007
On Jul 4, 11:25 am, "Victor" <vic...@noemail.noemail> wrote:
> Hi. all
> I have a customize web control. I have three simple properties and
> customized render class. then I add this control into my datalist like
> <aspataList ID="datalist" runat="server" RepeatColumns="3">
> <ItemTemplate>
> <uc:mycontrol id="test" runat="server" />
> </ItemTemplate>
> </aspataList>
> In the code-behind I have something like
> List<mycontrol > lst = new List<mycontrol >;
> lst.add(new mycontrol ());
> lst.add(new mycontrol ());
> lst.add(new mycontrol ());
> datalist.datasource= lst;
> datalist.databound();
>
> But i found the control can not be rendered properly. Instead of displaying
> four images, no images has been shown. What did I do wrong here? Can someone
> give me some reference on how to add your customized control to datalist
> then bind the value and render it properly.
>
> Cheers
> Thanks a lot
> Victor


Hi victor ...

not getting the actual picture what is going on... any way...
http://msdn2.microsoft.com/en-us/library/ms366538.aspx
http://msdn2.microsoft.com/en-us/library/ms366539.aspx
here is two link which demonstrated how to build a custom databound
control...

Thanks
Munna
www.kaz.com.bd
http://munnacs.110mb.com

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-04-2007
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.


 
Reply With Quote
 
Victor
Guest
Posts: n/a
 
      07-04-2007
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<MyControl> lstResult = 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]" <> wrote in message
news:...
> 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.
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-05-2007
Thanks for your reply Victor,

Well, I've performed some local test through the custom control you
provided. It seems I can correctly make the "MyControl" display image
(through databinding) well in DataList. I think there might be something
incorrect with your aspx template of the DataList, would you also provide
it so that we can have a check? Anyway, below is my test page's aspx
template and code behind for your reference:


===========aspx================
<aspataList ID="DataList1" runat="server">
<ItemTemplate>
MYControl:
<cc1:MyControl ID="MyControl1" runat="server"
ImagePath='<%# Eval("ImagePath") %>' />
</ItemTemplate>
</aspataList>

========code behind============
protected void Page_Load(object sender, EventArgs e)
{
BindList();
}

protected void BindList()
{
MyControl[] mcs = new MyControl[5];

for (int i = 0; i < mcs.Length; i++)
{
mcs[i] = new MyControl();
mcs[i].ID = "mc_" + i;
mcs[i].MyControlID = i;
mcs[i].ImagePath =
"http://static.asp.net/asp.net/images/MicrosoftASPNET.gif";

}

DataList1.DataSource = mcs;
DataList1.DataBind();

}
=============================

the "MyControl"'s code is identical to yours. If you have any questions on
this, 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.





 
Reply With Quote
 
Victor
Guest
Posts: n/a
 
      07-05-2007
Hi Steven:
thanks so much for your help. The problem is solved. The problem is I did
not bind the properties properly..
Thanks again for the help


"Steven Cheng[MSFT]" <> wrote in message
news:...
> Thanks for your reply Victor,
>
> Well, I've performed some local test through the custom control you
> provided. It seems I can correctly make the "MyControl" display image
> (through databinding) well in DataList. I think there might be something
> incorrect with your aspx template of the DataList, would you also provide
> it so that we can have a check? Anyway, below is my test page's aspx
> template and code behind for your reference:
>
>
> ===========aspx================
> <aspataList ID="DataList1" runat="server">
> <ItemTemplate>
> MYControl:
> <cc1:MyControl ID="MyControl1" runat="server"
> ImagePath='<%# Eval("ImagePath") %>' />
> </ItemTemplate>
> </aspataList>
>
> ========code behind============
> protected void Page_Load(object sender, EventArgs e)
> {
> BindList();
> }
>
> protected void BindList()
> {
> MyControl[] mcs = new MyControl[5];
>
> for (int i = 0; i < mcs.Length; i++)
> {
> mcs[i] = new MyControl();
> mcs[i].ID = "mc_" + i;
> mcs[i].MyControlID = i;
> mcs[i].ImagePath =
> "http://static.asp.net/asp.net/images/MicrosoftASPNET.gif";
>
> }
>
> DataList1.DataSource = mcs;
> DataList1.DataBind();
>
> }
> =============================
>
> the "MyControl"'s code is identical to yours. If you have any questions
> on
> this, 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.
>
>
>
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-06-2007
You're welcome


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort list doesnt work, key=str still doesnt work notnorwegian@yahoo.se Python 3 05-27-2008 04:32 AM
IE6 doesnt render the page properly whereas IE7 does =?Utf-8?B?QWxleCBGaW1pbmU=?= ASP .Net 2 08-31-2007 02:15 PM
.NET 2.0 Composite Control with DataList won't render jeff_suhr ASP .Net 0 09-27-2006 09:00 PM
PC doesnt boot first time and doesnt shutdown dann Computer Support 6 08-21-2006 07:31 AM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57