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>
Related
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>
so basically I have a query that populates a table in an asp page like so:
<div class="span10">
<table class="table table-bordered table-striped with-check" runat="server" id="noncompulsarymodules">
<tbody>
<tr>
<td><asp:Label ID="Label3" runat="server" Text= '<%# Eval("ModuleId") %>' style="display:none;" /> </td>
<td><asp:Label ID="Label1" runat="server" Text= '<%# Eval("noncompcode") %>' /> </td>
<td><asp:Label ID="Label2" runat="server" Text= '<%# Eval("noncomptitle") %>' /> </td>
<td><asp:Label ID="Label4" runat="server" Text= '<%# Eval("moduleunits") %>' /> </td>
<td class="center" style="overflow:hidden;"> <asp:Label ID="ModuleDescription" runat="server" Text='<%# Eval("noncompdesc") %>' /></td>
<td><input type="checkbox" /></td>
</tr>
</tbody>
</table>
</div>
basically what I want to do is cycle through the table and take the rows that have been checked and put them into a query.
Any tips would be greatly appreciated!
Have a look at using an ASP.Net Gridview control with a checkbox / templatefield column.
You will then be able to iterate through the GridViewRows and get the checked columns.
I am using a ListView that contains a checkbox. I would like the checkbox to automatically update a bit field in my database from False to True (or visa versa) when the box is checked.
I am not familiar with the update panel and I'm struggling to find a way to achieve this.
My List View
<asp:ListView ID="ListView1" runat="server" DataKeyNames="NotificationID" DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No notifications exist.<br /> NOTE: You must be logged in to see notificaitons</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr class="odd gradeX">
<td><span style="display: none;"><%# ("00000000" + Eval("DateDescNumber")).TxtStrRight(8) %> - </span><%# GlobalUtilities.GetDiffDate(Convert.ToDateTime(Eval("DateTimeLogged"))) %></td>
<td><%# Eval("UserName") %></td>
<td><%# Eval("NotificationTitle") %></td>
<td class="center"><%# Eval("NotificationMessage") %></td>
<td class="center">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:updatepanel id="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBoxMarkedAsRead" runat="server"
Checked='<%# Eval("MarkedAsRead") %>'
AutoPostBack="true"
Visible="true"
Text =" Not Selelected"
oncheckedchanged="CheckBox_MarkedAsRead_CheckedChanged" />
</ContentTemplate>
</asp:updatepanel>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table cellpadding="0" cellspacing="0" border="0" class="responsive dynamicTable display table table-bordered" width="100%">
<thead>
<tr>
<th style="width:80px">Date</th>
<th>From</th>
<th>Notice</th>
<th>Description</th>
<th class="ch" style="width:53px;">Read</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</tbody>
</table>
</LayoutTemplate>
</asp:ListView>
I have gone as far as creating the CheckBox_MarkedAsRead_CheckedChanged event in my Code behind (at least I think this is what I should do) but my attempts to script a solution in the code behind has been fail after fail.
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>
Can i in GridView add css to only first(headr) tr. I know how to add css to th inside header trr but i don't know if is possible to add css to trr?
GRIDVIEW:
<asp:GridView ID="gwCompanies" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Ime">
<ItemTemplate>
<asp:Image ID="imgServiceOpen" runat="server" ToolTip="Restavracija sprejema naročila" ImageUrl="~/Images/cheff-icon.png" Visible='<%# Convert.ToBoolean(Eval("ServiceOpen")) %>' />
<asp:HyperLink ID="hlEdit" runat="server" NavigateUrl='<%# GetOrderArticlesUrl(Eval("CompanyId")) %>'>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Naslov">
<ItemTemplate>
<asp:Label ID="lblFullAddress" runat="server" Text='<%# GetFullCompanyAddress(Container.DataItem) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label ID="lblEmptyCompaniesGrid" runat="server" Text="Ne najdem restavracij!"></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
output i want
<table id="rest_list">
<tr class="top_tab">
<td class="top_tab_title">Ime</td>
<td class="top_tab_title">Naslov</td>
</tr>
<tr>
<td class="rest_name">Murka</td>
<td>Točen naslov pizzerije</td>
</tr>
<tr>
<td class="rest_name">Lastoria</td>
<td>Točen naslov pizzerije</td>
</tr>
<tr>
<td class="rest_name">Skok</td>
<td>Točen naslov pizzerije</td>
</tr>
<tr>
<td class="rest_name">Tara</td>
<td>Točen naslov pizzerije</td>
</tr>
</table>
You can add a class with the HeaderStyle property, like this:
<asp:GridView ID="gwCompanies" runat="server" AutoGenerateColumns="false">
<HeaderStyle CssClass="top_tab" />
Or in the GridView tag, like this:
<asp:GridView ID="gwCompanies" runat="server" HeaderStyle-CssClass="top_tab" AutoGenerateColumns="false">
Not sure I understand correctly, but you should use a HeaderTemplate to define your header row, e.g:
<asp:TemplateField HeaderText="Ime">
<ItemTemplate>
...
</ItemTemplate>
<HeaderTemplate>
put here the content for the header row of this column
</HeaderTemplate>
</asp:TemplateField>
Then you can apply whatever style you want to your header.