472,347 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 software developers and data experts.

Customized Control in the Datalist doesnt render

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
<asp:DataList ID="datalist" runat="server" RepeatColumns="3">
<ItemTemplate>
<uc:mycontrol id="test" runat="server" />
</ItemTemplate>
</asp:DataList>
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


Jul 4 '07 #1
6 2132
On Jul 4, 11:25 am, "Victor" <vic...@noemail.noemailwrote:
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
<asp:DataList ID="datalist" runat="server" RepeatColumns="3">
<ItemTemplate>
<uc:mycontrol id="test" runat="server" />
</ItemTemplate>
</asp:DataList>
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

Jul 4 '07 #2
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.
Jul 4 '07 #3
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.


Jul 4 '07 #4
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================
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
MYControl:
<cc1:MyControl ID="MyControl1" runat="server"
ImagePath='<%# Eval("ImagePath") %>' />
</ItemTemplate>
</asp:DataList>

========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.

Jul 5 '07 #5
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]" <st*****@online.microsoft.comwrote in message
news:0j**************@TK2MSFTNGHUB02.phx.gbl...
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================
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
MYControl:
<cc1:MyControl ID="MyControl1" runat="server"
ImagePath='<%# Eval("ImagePath") %>' />
</ItemTemplate>
</asp:DataList>

========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.



Jul 5 '07 #6
You're welcome :-)
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

Jul 6 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Art Kedroski | last post by:
We are using .NET validators on most of our aspx pages. When the validator is contained within a datalist (i.e. the EditItemTemplate) the...
0
by: Kyong Kwak | last post by:
Hey all, wanted to know if I can cache an entire control.. this is what I have.. Webform has header, nav, footer, and Usercontrol_1. ...
5
by: Web Team | last post by:
Hi All, Can someone please explain how I go about adding a control (Say for example a panel) to a custom web control. I've tried this:...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the...
1
by: Jameel | last post by:
Hi Coders, How do i Add a Lable control to DataList to show the Count Files which belong the current Category. i have a DataList which...
0
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView...
0
by: JP | last post by:
I have a DataList control that contains a TABLE in it. I am evaluating weather or not the DateTime value coming back from DataBinder.Eval is blank...
0
by: Savas Ates | last post by:
I have a simple Data list control in my user control. When I run my main page and i use response.write to see grid query it writes 2 times. I...
1
by: | last post by:
I use a variety of controls made by a variety of vendors, including Microsoft. In general the level of development on gridview-like...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.