DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

Create control according to their data type

This is a discussion on Create control according to their data type within the .Net Development forums, part of the Programming & Scripting category; I would use a direct SQL data reader... Only thing to remember with a repeater is the control itself doesn't ...

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

  #11  
Old January 19th, 2009, 10:46 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

I would use a direct SQL data reader...

Only thing to remember with a repeater is the control itself doesn't render anything. So, unlike a gridview (I think) it won't put a <table> tag or <tr><td> tags for each row. All it does is render the details inside the various templates (Item, Alternating etc.) for each record in the datasource.

Hope that helps.

Comments on this post
guddu agrees: Thanked Post
jmurrayhead agrees:
mehere agrees:
__________________
Join the folding team
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
guddu (January 19th, 2009)
  #12  
Old January 19th, 2009, 11:45 AM
guddu's Avatar
Barn Enthusiast
 
Join Date: Jul 2008
Location: Oxford UK
Posts: 334
Rep Power: 2
guddu is on a distinguished road
Default

last doubt how to use repeater control with business and data layer.
any sample code u refer?
__________________
Love is physical attraction and mental destruction
Reply With Quote
  #13  
Old January 19th, 2009, 12:00 PM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

You just set the datasource of the repeater to the function that returns the data from the database.
Code:
sub Page_Load()
 
If Not IsPostback then
    repeater1.Datasource = BLL.GetData()
    repeater1.Databind()
End If
 
End Sub
Code:
<asp:repeater id="repeater1" runat="server" OnItemDataBind="repeater1_OnItemDataBind">
.
.
</asp:repeater>
Code:
Sub repeater1_OnItemDataBind(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItem.AlternatingItem then
  Dim objBOL As BOLObject = e.Item.DataItem
  If objBOL.your_property = "whatever" then
       'do this
  End if
End If
End Sub
Hope that helps.
Reply With Quote
  #14  
Old January 21st, 2009, 11:45 AM
guddu's Avatar
Barn Enthusiast
 
Join Date: Jul 2008
Location: Oxford UK
Posts: 334
Rep Power: 2
guddu is on a distinguished road
Default

hi
i want to give unique id to my text box .i m getting server tag not well formed tag?
Code:
<asp:TableCell runat="server" Width="10%">
                                    <asp:TextBox runat="server" ID="txtBox<%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>"></asp:TextBox>
                                    <asp:ListBox runat="server" ID="lstBox<%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>"></asp:ListBox>
                                </asp:TableCell>
Reply With Quote
  #15  
Old January 21st, 2009, 11:48 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

Try changing the " to '
Code:
<asp:TableCell runat="server" Width="10%">
                                    <asp:TextBox runat="server" ID='txtBox<%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>'></asp:TextBox>
                                    <asp:ListBox runat="server" ID='lstBox<%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>'></asp:ListBox>
                                </asp:TableCell>
Reply With Quote
  #16  
Old January 21st, 2009, 11:52 AM
guddu's Avatar
Barn Enthusiast
 
Join Date: Jul 2008
Location: Oxford UK
Posts: 334
Rep Power: 2
guddu is on a distinguished road
Default

now getting below error
Error1 'txtBox<%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>'
is not a valid identifier.
Reply With Quote
  #17  
Old January 21st, 2009, 12:03 PM
guddu's Avatar
Barn Enthusiast
 
Join Date: Jul 2008
Location: Oxford UK
Posts: 334
Rep Power: 2
guddu is on a distinguished road
Default

hi
and with above i m looking for this also.
Code:
<ItemTemplate>                        
                        <asp:Table runat="server" Width="60%" HorizontalAlign="Center">
                            <asp:TableRow runat="server">
                                <asp:TableCell runat="server" Width="10%">
                                    <%# DataBinder.Eval(Container.DataItem, "Description")%>
                                </asp:TableCell>
                                <asp:TableCell runat="server" Width="10%">
                                    <%# DataBinder.Eval(Container.DataItem, "DataType")%>
                                    +
                                    <%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>
                                </asp:TableCell>
                                <asp:TableCell runat="server" Width="10%">
                                    <asp:TextBox runat="server" ID='txtBox<%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>'></asp:TextBox>
                                    <asp:ListBox runat="server" ID='lstBox<%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%>'></asp:ListBox>
                                </asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>                             
                    </ItemTemplate>
if <%# DataBinder.Eval(Container.DataItem, "DataTypeN0")%> value of this 4 then it will display only text box and if value is 5 then will display only select box.how to check such a condition here??
Reply With Quote
  #18  
Old January 21st, 2009, 12:22 PM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

.NET assigns unique IDs to controls automatically. Is there any reason you want to change them to something else?

If you want to make changes to the IDs of controls etc. and also for checking values of items and changing the details displayed accordingly, use the OnItemDataBound method of your repeating control.

Then, for each item it binds, you can retrieve the controls and values and make any alterations before the code is rendered.

Hope that helps.
Reply With Quote
  #19  
Old January 21st, 2009, 01:02 PM
guddu's Avatar
Barn Enthusiast
 
Join Date: Jul 2008
Location: Oxford UK
Posts: 334
Rep Power: 2
guddu is on a distinguished road
Default

hi Thanks for a reply.i skipped the idea of assigning id.and for display purpose i m doing like this and i think i m fine with this
Code:
<asp:TextBox runat="server" Visible='<%#VisibleTextBoxYesNo(DataBinder.Eval(Container .DataItem,
                                    "DataTypeN0").ToString())%>' ID='txtBox'></asp:TextBox>

protected bool VisibleTextBoxYesNo(string val)
        {
            if (val == "1" || val == "2" || val == "3")
                return (true);

            return (false);
        }
Reply With Quote
  #20  
Old January 21st, 2009, 01:05 PM
guddu's Avatar
Barn Enthusiast
 
Join Date: Jul 2008
Location: Oxford UK
Posts: 334
Rep Power: 2
guddu is on a distinguished road
Default

now i m facing problem with paging in repeater.i m using datasource to make paging work but i m getting below error at bind line.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Code:
PackageList dd = PackageListBL.GetExtraInfo(121);

if (dd != null)
{

    PagedDataSource objPds = new  PagedDataSource();
    objPds.DataSource = dd;
    objPds.AllowPaging = true;
    objPds.PageSize = 5;
    objPds.CurrentPageIndex = CurrentPage - 1;
    rptExtraInfo.DataSource = objPds;
    rptExtraInfo.DataBind();
}
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Create/Print Form data Rebelle ASP Development 5 December 10th, 2008 10:25 AM
Binding data to the RadioButtonList Control Shem .Net Development 2 December 3rd, 2008 02:42 AM
The data source 'ObjectDataSource1' does not support sorting with IEnumerable data Shem .Net Development 5 June 25th, 2008 08:07 AM
Data Type Mismatch in Criteria Expression alansidman Microsoft Access 1 April 9th, 2008 04:33 PM
[Error] Type mismatch: HTMLEncode Rebelle ASP Development 20 March 28th, 2008 09:30 AM


All times are GMT -4. The time now is 02:33 AM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2