Respected Viewers I need only a specific column does not repeat again and again in Gridview I attache a screenshot in you can see room charges repeat 3 times but I need to this repeat only one time and then its charges and date are shown in simple language it is a heading Please review
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Width="100%" BorderWidth="0px" BorderStyle="None" OnRowDataBound="GridView1_RowDataBound" ShowFooter="true" OnDataBound="GridView1_DataBound">
<Columns>
<asp:TemplateField HeaderStyle-BorderStyle="None" ItemStyle-BorderStyle="None" FooterStyle-BorderStyle="None" >
<ItemTemplate>
<table style="width:100%;font-size:12px;text-align:left">
<tr>
<td colspan="5">
<table style="width:100%;font-size:16px; font-weight:bold; font-family:Cambria, Cochin, Georgia, Times, Times New Roman, serif;text-align:left;margin-bottom:10px">
<tr><td><u> <asp:Label ID="lblprintheading" runat="server" Text='<%#Eval("Headingname")%>' ></asp:Label></u>
</td></tr>
</table>
</td>
</tr>
<tr>
<td style="width:10%;">
<asp:Label ID="lblservicedate" runat="server" Text='<%#Eval("Date")%>'></asp:Label>
</td> <td style="width:50%;">
<asp:Label ID="lblparticular" runat="server" Text='<%#Eval("Servicename")%>'></asp:Label> (<asp:Label ID="Label22" runat="server" Text='<%#Eval("doctorname")%>'></asp:Label>)
</td>
<td style="width:10%;">
<asp:Label ID="lblrate" runat="server" Text='<%#Eval("Rate")%>'></asp:Label>
</td>
<td style="width:10%;">
<asp:Label ID="lblnos" runat="server" Text='<%#Eval("Qty")%>'></asp:Label>
</td>
<td style="width:20%;">
<asp:Label ID="lblprice" runat="server" Text='<%#Eval("Nettotal")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate >
<table style="width:100%;text-align:center; border:0px none">
<tr>
<td colspan="5" style="text-align:right;padding-right:50px"> ..................................................................................</td>
</tr>
<tr>
<td style="width:10%;">
</td> <td style="width:50%;">
</td>
<td style="width:10%;">
</td>
<td style="width:10%; font-size:18px; font-weight:bold;">
Total:
</td>
<td style="width:20%;">
<asp:Label ID="Label18" runat="server" Text='<%#Eval("Nettotal")%>'></asp:Label>
</td>
</tr>
</table>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
https://i.stack.imgur.com/6Rl6K.png
You can use nested grid view. Which will give you perfect result as you want.
Related
I am new to ASP.NET. I have taken a Panel. Inside the Panel, I have taken a table. Inside the table there are TextBox, RadioButton and a Button controls.
I have written some code in button_click event.
But nothing happens. button_click event is not firing.
What to do now ?
I have also some other things in panel. But no click event is working.
Code is below:
<asp:Panel ID="Pnlproducts" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<asp:DataList ID="DLProducts" runat="server" RepeatColumns="3" Width="600px" OnSelectedIndexChanged="DLProducts_SelectedIndexChanged">
<ItemTemplate >
<table align="left" class="auto-style6" style="border-color:#9900FF;border-left:1px;border-right:1px;border-top:1px;">
<tr>
<td style="border-color: #000000; border-width: 1px; border-bottom-style: ridge" class="auto-style8">
<asp:Label ID="lblProductName" runat="server" Text="<%# Bind('ProductName') %>" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style9">
<asp:Image ID="Image2" runat="server" Height="160px" ImageUrl="<%# Bind('ProductImage') %>" Width="173px" Style="border:ridge 1px black" />
</td>
</tr>
<tr>
<td class="auto-style9"><strong>Price:</strong><asp:Label ID="lblPrice" runat="server" Text="<%# Bind('ProductPrice') %>" Font-Bold="True" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style9">
<asp:Button ID="Addtocartbtn" runat="server" BorderStyle="Solid" BorderWidth="1px" OnClick="Addtocartbtn_Click" Text="Add to Cart" Width="170px" BorderColor="Black" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</asp:Panel>
<asp:Panel ID="Panel111" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<table class="auto-style16">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlCatagory" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<div class="auto-style7">
<asp:DataList ID="dlCatagory" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<asp:LinkButton ID="LBTNCatagoty" runat="server" CommandArgument="<%# Bind('CatagoryID') %>" Font-Bold="True" OnClick="LBTNCatagoty_Click" Text="<%# Bind('CatagoryName') %>"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
</asp:Panel>
<asp:Panel ID="Panel222" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<table class="auto-style10">
<tr>
<td class="auto-style7" colspan="2"><strong>Please Type Your Details</strong></td>
</tr>
<tr>
<td class="auto-style12"></td>
<td class="auto-style11"></td>
</tr>
<tr>
<td class="auto-style15">Name :</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxUserName" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">E-mail :</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxEmail" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Address:</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxAdress" runat="server" Height="90px" TextMode="MultiLine" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Gender :</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="GenderGroup" Text="Male" /><br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="GenderGroup" Text="Female" />
</td>
</tr>
<tr>
<td class="auto-style15">Mobile:</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxMobileNum" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Photo :</td>
<td class="johnykbd8">
<asp:FileUpload ID="FileUploaduserphoto" runat="server" Width="180px" />
</td>
</tr>
<tr>
<td class="auto-style15">Payment :</td>
<td>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="Paymentgroup" Text="Visa" /><br />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="Paymentgroup" Text="MasterCard" /><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="Paymentgroup" Text="Cash On Delivery" />
</td>
</tr>
<tr>
<td class="auto-style15">Review :</td>
<td>
<asp:TextBox ID="TextBoxreview" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Total : </td>
<td>BDT :<asp:Label ID="Labelshopamount" runat="server"></asp:Label></td>
</tr>
<tr>
<td colspan="2">
<asp:ImageButton ID="ImageButtonOrderNow" runat="server" ImageUrl="~/Images/Designing/order.jpg" OnClick="ImageButtonOrderNow_Click" Width="250px" />
</td>
</tr>
</table>
</asp:Panel>
If the button is in a datalist or gridview for example, set the CommandName property. The databound object (datalist, gridview) has ItemCommand-event. Put the code in this event.
Pseudo code:
if (e.CommandName.equals(your_command_name)){ label1.text = e.CommandArgument };
Here is my aspx code. im using a formview and fixed values in which i used an asp.label. but when i run it, formview doesnt show up. i dont have any code behind in which i think i lack? i really appreciate any help. thanks in advance!
<asp:FormView ID="EmployeeFormView" HorizontalAlign="Center"
DataKeyNames="ID"
Gridlines="Both"
RunAt="server"
BackColor="#FFFF66"
BorderColor="#FF8080">
<HeaderStyle backcolor="Navy"
forecolor="#999966"/>
<RowStyle backcolor="White" ForeColor="#CC3300"/>
<EditRowStyle backcolor="#FFFFFF" ForeColor="#FF9966"/>
<ItemTemplate>
<table id="tblcustomerprofile" border="1" cellpadding="1" cellspacing="0">
<tr>
<td style="width:100px">
ID:
</td>
<td style="width:250px">
<asp:Label ID="Label1" runat="server" Text="10999574"></asp:Label>
</td>
<tr>
<td style="width:100px">
Name:
</td>
<td style="width:250px">
<asp:Label ID="Label2" runat="server" Text="Paolo Duhaylungsod"></asp:Label>
</td>
<tr>
<td>
Age:
</td>
<td>
<asp:Label ID="Label12" runat="server" Text="24"></asp:Label>
</td>
<tr>
<td>
Birth Date:
</td>
<td>
<asp:Label ID="Label13" runat="server" Text="06/29/1990"></asp:Label>
</td>
</tr>
<tr>
<td>
Citizenship:
</td>
<td>
<asp:Label ID="Label14" runat="server" Text="Filipino"></asp:Label>
</td>
<tr>
<td>
Status:
</td>
<td>
<asp:Label ID="Label15" runat="server" Text="Single"></asp:Label>
</td>
</tr>
<tr>
<td style="width:100px">
Email Address:
</td>
<td style="width:250px">
<asp:Label ID="Label3" runat="server" Text="paolodexter#yahoo.com"></asp:Label>
</td>
<tr>
<td style="width:100px">
College:
</td>
<td style="width:250px">
<asp:Label ID="Label4" runat="server" Text="De La Salle- College of Saint Benilde"></asp:Label>
</td>
<tr>
<td>
Course:
</td>
<td>
<asp:Label ID="Label5" runat="server" Text="BS- Information Systems"></asp:Label>
</td>
<tr>
<td>
Contact Number:
</td>
<td>
<asp:Label ID="Label6" runat="server" Text="09255666167"></asp:Label>
</td>
</tr>
<tr>
<td>
Address:
</td>
<td colspan="3">
<asp:Label ID="Label7" runat="server" Text="Bf Resort Village, Las Pinas"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<EmptyDataTemplate>
I believe you need to add the default mode property to your formview.
defaultmode="Edit"
without this the formview would be set to show the empty data template.
You could also try to just add all of your code to the empty data template of the formview then it should all show up
This is my repeater control with data coming from [Patient_Master] table. But Visit_Date is coming from [Patient_Visit] table. How can I show Visit_Date to the same repeater? Is it possible to give two datasources to one repeater? [Patient_Master] and [Patient_Visit] have a relation:
<asp:Repeater ID="repeaterPatientList" runat="server" OnItemDataBound="repeaterPatientList_ItemDataBound" >
<ItemTemplate>
<tr onclick="selectRow(this);">
<td class="csstablelisttd" style="display:none" >
<asp:Label ID="lblPID" runat="server" Text='<%#Eval("PID")%>'></asp:Label>
</td>
<td class="csstablelisttd" >
<%#Eval("Patient_Name")%>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblPatientName" runat="server" Text='<%#Eval("Patient_ID")%>'></asp:Label>
</td>
<td class="csstablelisttd" >
<asp:Label ID="lblSex" runat="server" Text='<%#Eval("Sex")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%#Eval("Patients_Birth_Date")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblLastVisitDate" runat="server" Text='<%#Eval("Visit_Date")%>'></asp:Label>
</td>
<td class="csstablelisttd">
New
</td>
<td id="tdTodaysVisit" bgcolor="#00cc66" runat="server">
<span class="cssgreen">Today's Visit</span>
</td>
<td class="csstablelisttd">
<%--<asp:HyperLink ID="lnkSchedule" CssClass="csshyperlinkSchedulePatient" runat="server" NavigateUrl='<%# Eval("PID", "~/Create_Order.aspx?ID={0}") %>'>Schedule</asp:HyperLink>--%>
Schedule
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Why don't you use an outer join between patient_master and patient_visit.
I got a table with 2 nested tables inside that display my two repeaters. My repeaters display Home and office addresses respectively. The problem is that whenever I add a new record in one repeater, the other repeater table's display gets messed up. Like if I add a record in rpt1 , then table for rpt1 moves up and table for rpt2 goes down..ie the headers do not display in one single line . They move up and down when records are added or deleted. WHat I want is these headers to be fixed so if I add new records or delete records, the headings of both repeaters display on the same line...How do I fix this ? Hope its not confusing.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<asp:Panel ID="pnlAddAddress" runat="server">
<asp:Repeater ID="rpt1" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">
<HeaderTemplate>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressB" runat="server" Text='<%# Eval("Address1")%>' CommandName="DisplayAddressB" CommandArgument='<%#Eval("AddID") %>' CausesValidation=false></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<%-- Visible='<%# Eval("IsDefault")%>'--%>
<asp:LinkButton ID="lnkDefaultB" Text="Set as Default" CommandName="SetDefaultB" runat="server" CommandArgument='<%# Eval("AddID") + "," + Eval("IsB") %>'
CausesValidation="false" Visible='<%# Eval("IsDefault")%>'></asp:LinkButton>
<asp:Label ID="labelDefaultB" Text="Yes" runat="server" Visible='<%# Eval("IsDefault")%>'></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlSping" runat="server">
<asp:Repeater ID="rpt12" OnItemCommand="rpt12_ItemCommand" runat="server" OnItemDataBound="rptSpping_OnItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressS" runat="server" Text='<%# Eval("Address1")%>' CommandArgument='<%#Eval("AddID") %>' CommandName="DisplayAddressS" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<asp:LinkButton ID="lnkDefaultS" Text="Set as Default" CommandName="SetDefaultS" runat="server" Visible=true CommandArgument='<%# Eval("AddID") + "," + Eval("IsS") %>'
CausesValidation="false"></asp:LinkButton>
<asp:Label ID="labelDefaultS" Text="Yes" runat="server" Visible=true></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" Text="Edit" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
</tr>
</table>
Use css attribute valign and set its value to top like this <td width="50%" valign="top">.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" valign="top">
<asp:Panel ID="pnlAddAddress" runat="server">
......
</asp:Panel>
</td>
<td valign="top">
<asp:Panel ID="pnlSping" runat="server">
......
</asp:Panel>
</td>
</tr>
</table>
For headers look to use the <th> element, this will keep them at the top of the table.
Put the <table> tags you do have outside your repeater controls, make sure the repeater only renders a single row and the same for the header.
Unless you have good reason consider just wrapping the two tables in <div> tags as nested tables really don't work ideally for layout.
I have a Datalist. Following is the structure of the ItemTemplate:
<ItemTemplate>
<div id="driversGrid" runat="server" style="width:3500px;" >
<table cellpadding="0" cellspacing="0" border="0" width="3500px">
<tr>
<td id="Td1" runat="server" style="visibility:hidden;">
<asp:Label ID="lblID" runat="server" BackColor="White" Font-Bold="true" Text='<%# Eval("ID") %>' /><br />
</td>
<td id="title" style="width:90px;text-align:center;">
<asp:Label ID="lblTitle" runat="server" BackColor="White" Font-Bold="true" Text='<%# Eval("Name") %>' /><br />
</td>
<td id="am0900" runat="server" style="width:90px;"> </td>
<td id="am0915" runat="server" style="width:90px;"> </td>
<td id="am0930" runat="server" style="width:90px;"> </td>
<td id="am0945" runat="server" style="width:90px;"> </td>
<td id="am1000" runat="server" style="width:90px;"> </td>
<td id="am1015" runat="server" style="width:90px;"> </td>
<td id="am1030" runat="server" style="width:90px;"> </td>
<td id="am1045" runat="server" style="width:90px;"> </td>
<td id="am1100" runat="server" style="width:90px;"> </td>
</tr>
</table>
</div>
</ItemTemplate>
Now, at the itemdatabound event, I fetch multiple time (data) from the database in form 10:25 AM.
I manipulate each data and convert it to am1030 (similar to one of the td ID in itemTemplate). Now I want to check each td in ItemTemplate and compare the lblID (i.e. the staff ID) to the ID in my variable and then compare the tdID to the manipulated data. If they match change the background color of the td.
In short, I want to check that if the lblID is 3 then get the td with ID am1030 and change the background color.
Needs to be done in C#.net.
Use a foreach loop to iterate through the e.Item.Controls collection, like this -
foreach (Control c in e.Item.Controls)
{
//if c is HtmlCell, then check the ID and change the color.
}