I display the list of table names when a particular database is selected from the drop down list. Number of tables in my database is more than 100. I don't want to display it as a single column and scroll the page. I want to display it as a table. Also each table name is a link to view its corresponding table details. can anyone help me with the technique to achieve it ?
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td colspan="5">
Tables
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<%--<tr>--%>
<td><asp:Label ID="lbl_TableName" runat="server" Text='<%#Eval("table_name")%>' /></td>
<%-- </tr>--%>
</ItemTemplate>
<%-- <SeparatorTemplate>
<td colspan="4"> name</td>
</SeparatorTemplate>--%>
<%-- <AlternatingItemTemplate>
<td> break</td>
</AlternatingItemTemplate>--%>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Related
I want to fill my ListView from codebehind and want to know how to build the fields.
I saw this example, and I'd like to now if the only way to build a ListViews fields is using tables. If not, what would be another way to do that? I tried only filling the ListView with datasource, like this:
ListView1.DataSource = ds;
ListView1.DataBind();
But it gave me an error:
An ItemTemplate must be defined on ListView 'ListView1'.
What is the best way to use ListView? The error happens only when I use ListView1.DataBind();
PS: I'll need only one row to display, so if someone has a better control to use than ListView, I'm reading.
UPDATE
Now I'm trying like this:
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table border="0" cellpadding="1">
<tr style="background-color: #E5E5FE">
<th align="left"><asp:LinkButton ID="lnkResp" runat="server"></asp:LinkButton></th>
<th align="left"><asp:LinkButton ID="lnkProj" runat="server"></asp:LinkButton></th>
<th align="left"><asp:LinkButton ID="lnkFunc" runat="server"></asp:LinkButton></th>
<th<></th>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:Label runat="server" ID="lblResp"><%#Eval("responsavel") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblProj"><%#Eval("projeto") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblFunc"><%#Eval("funcionalidade") %></asp:Label></td>
</tr>
</ItemTemplate>
</asp:ListView>
But I got a new error:
An item placeholder must be specified on ListView 'ListView1'.
Specify an item placeholder by setting a control's ID property to "itemPlaceholder".
The item placeholder control must also specify runat="server".
In your LayoutTemplate, you need a <asp:PlaceHolder runat="server" ID="itemPlaceholder" /> in the table tag.
<LayoutTemplate>
<table border="0" cellpadding="1">
<tr style="background-color: #E5E5FE">
<th align="left"><asp:LinkButton ID="lnkResp" runat="server"></asp:LinkButton></th>
<th align="left"><asp:LinkButton ID="lnkProj" runat="server"></asp:LinkButton></th>
<th align="left"><asp:LinkButton ID="lnkFunc" runat="server"></asp:LinkButton></th>
<th<></th>
</tr>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</table>
</LayoutTemplate>
I want to create DataList control and I want to have 2 columns first for "First Name" second for "Last Name". Like this:
First Name|Second Name
Peter   Johnson
John   Peterson
When I try with this code, isn't working. This isn't arrange the names as I want:
<asp:DataList ID="NamesDataList" runat="server" >
<HeaderTemplate>
First Name
Last Name
</HeaderTemplate>
<ItemTemplate>
<%# Eval("FirstName")%>
<%# Eval("LastName")%>
</ItemTemplate>
</asp:DataList>
I want to have DataList control like this one for example. https://www.packtpub.com/sites/default/files/Article-Images/asp.net-img03.png
Try this
<asp:DataList ID="NamesDataList" runat="server" >
<HeaderTemplate>
<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td><asp:Label ID="lblRaterName" runat="server" Text='<%# Eval("FirstName")%>'></asp:Label> </td>
<td><asp:Label ID="lblRaterName" runat="server" Text='<%# Eval("LastName")%>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
My object is to create something like table with number of columns and 5 rows.
I decided that i can do that with asp.net control repeater. Maybe there is a better way you should tell me?
So what i need as result is a number of columns in the first one there will be headers, in the next three rows it should be textboxes, with appropriete name like the txt+name of the header, and the last row should have checkboxes also with appropriete name.
So what i wanted to do is define one column as it should look like and then do the rest programmatically, or just bind IList (the names of the headers) and the other columns should be created.
Is this possible and how to do that?
What i have now is something like that:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1" width="100%">
<tr>
<td>%#Container.DataItem("value")%</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:TextBox ID="TextBox1" runat="server"/></td>
<td><asp:TextBox ID="TextBox2" runat="server"/></td>
<td><asp:TextBox ID="TextBox3" runat="server"/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I have a ListView Control in Asp.net 4.0 C#
I am attempting to make the default mode = Edit Mode with text boxes. So I took the Item Template (the default template) and replaced my databound labels with TextBoxes.
It works ok. Except the text Boxes only apply to every other row. So half the rows are text boxes on Page Load and half the Roes are still Labels. Here is my code:
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
</td>
<td>
<asp:TextBox ID="DiscountPercentageTextBox" runat="server"
Text='<%# Bind("DiscountPercentage") %>' />
</td>
<td>
<asp:TextBox ID="CashTextBox" runat="server" Text='<%# Bind("Cash") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table>
<thead>
<tr>
<th>Title </th>
<th>DiscountPercentage</th>
<th>Cash</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</tbody>
</table>
</LayoutTemplate>
And here is the result:
You see? Every other row is a textbox. I need all rows to be textboxes. What am i doing wrong?
Huh, do you have an AlternatingItemTemplate defined? The ListVIew has no intelligence to make the original fields as labels....
Try making the ALternatingItemTemplate as the ItemTemplate too, if you don't have one defined.
I have an asp.net web page that's has a number of controls that are repeated according to number of records retrieved from the database, and I wanna read the values of those text boxes after users enter values in them, so please if anyone can help me on this issue.
I have an example of my work
<% System.Data.SqlClient.SqlDataReader myDReader = myDatabaseConnector.getDataFromDBAsSQLDataReader("SELECT * from students);
while(myDReader.Read())
{ %>
<asp:TextBox ID="txtCourseInfo" Test="" EnableViewState="false" CssClass="dataEntrySearchDataText" ReadOnly="true" runat="server"></asp:TextBox>
<% } %>
This a sample of what I have mean from my question in which I want to retrieve the value of txtCourseInfo in my C# code behind
You could use a Repeater to do this:
<asp:repeater id="rptCourses" runat="server" DataSourceID="dsCourseInfo"
<ItemTemplate>
<asp:TextBox ID="txtCourseInfo" Text='<%#Eval("StudentName")#%>' EnableViewState="false" CssClass="dataEntrySearchDataText" ReadOnly="true" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>
<asp:sqldatasource id="dsCourseInfo"
ConnectionString="<%$ ConnectionStrings:YourConnectionString %>"
Select Command="Select * from Students">
</asp:sqldatasource>
That's all you need. from code behind you can iterate through the controls on the repeater and grab the information.
Notice the Eval expression on the text field. I used "StudentName" as an example, but you should use one of the column names returned by the select statement
Additional comments:
Don't do select * from ... It's a bad practice in many respects. Always specify the columns you need, even if you need all.
I realize that you disable viewstate on the textbox. I don't know the reason for doing this but be aware that the info won't be persisted on subsequent postbacks unless you enable it on the control.
UPDATE
Yes, you can have tables inside repeaters. Look at the example below:
<ItemTemplate>
<table runat="server" style="color: White; background-color: #3A4F63;" visible="false"
id="headerTable">
<tr>
<td colspan="3" align="center">
<asp:Label ID="headerTitle" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 200px; background-color: #3A4F63; color: White;">
Image
</td>
<td style="width: 200px;">
Studen Name
</td>
<td style="width: 200px;">
Birth Date
</td>
</tr>
</table>
<table>
<tr>
<td style="width: 200px;">
<asp:Image ID="img" runat="server" ImageUrl='<%#Eval("ImageUrl") %>'></asp:Image>
</td>
<td style="width: 200px;">
<asp:Label ID="lblName" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</td>
<td style="width: 200px;">
<asp:Label ID="lblBirthDate" runat="server" Text='<%#Eval("BirthDate") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>