Asp.net and ListView Control - c#

I am printing data using List View control. I used LinkButton in itemtemplate. I want that column name should not be printed.....................................................
What changes i have to make?
<asp:ListView ID="ListView1" runat="server" DataKeyNames="userid" DataSourceID="SqlDataSource1">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="catgLabel" runat="server" Text='<%# Eval("catg") %>' />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:Label ID="datetimeLabel" runat="server" Text='<%# Eval("datetime") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:TextBox ID="catgTextBox" runat="server" Text='<%# Bind("catg") %>' />
</td>
<td>
<asp:Label ID="useridLabel1" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:TextBox ID="datetimeTextBox" runat="server" Text='<%# Bind("datetime") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="catgTextBox" runat="server" Text='<%# Bind("catg") %>' />
</td>
<td>
<asp:TextBox ID="useridTextBox" runat="server" Text='<%# Bind("userid") %>' />
</td>
<td>
<asp:TextBox ID="datetimeTextBox" runat="server" Text='<%# Bind("datetime") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="catgLabel" runat="server" Text='<%# Eval("catg") %>' />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:Label ID="datetimeLabel" runat="server" Text='<%# Eval("datetime") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">catg</th>
<th runat="server">userid</th>
<th runat="server">datetime</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="catgLabel" runat="server" Text='<%# Eval("catg") %>' />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:Label ID="datetimeLabel" runat="server" Text='<%# Eval("datetime") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>

Try setting ListView's HeaderStyle property to None. It can take 3 values:
a. None
b. Nonclickable
c. Clickable
The below exact texts from MSDN is sufficient::
The HeaderStyle property allows you to specify whether the column headers are visible or, if they are visible, whether they will function as clickable buttons. If the HeaderStyle property is set to ColumnHeaderStyle.None, the column headers are not displayed.
Let us know if you also tried the same or if different method, please post it here so as to be helpful to others.

Related

Render UserControl in Same line as other controls in a <td>

I want to render Usercontrol in the same line as my other controls in . By default, it renders in new line for user control.
Here is my Markup
<tr>
<td>
<asp:ContentPlaceHolder ID="TitleContentPlaceHolder" runat="server">
<asp:Label ID="lblTitle" runat="server" EnableTheming="False" Font-Size="Small" ForeColor="Green"
Font-Bold="True" Style="margin-left: 18px"></asp:Label>
<asp:HyperLink ID="gotoHyperLink" Visible="false" EnableTheming="False" Font-Size="Small"
ForeColor="Green" Font-Bold="True" Style="margin-left: 2px" runat="server" NavigateUrl=""
Target="_blank">- To Wiki</asp:HyperLink>
<uc1:GoToRequestControl ID="GoToRequestControl1" runat="server" />
</asp:ContentPlaceHolder>
</td>
</tr>
I want to render the UC1 in the same line as previous two controls in Div if possible after some spacing to the right. Any fix on how to achieve this?
My User Control is designed using despite that I want it to be on same line. Here is my Usercontrol's HTML
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Panel runat="server" DefaultButton="btnGo" BackColor="Transparent">
<table style="margin-left:18px">
<tr valign="top">
<td>
<b><asp:Literal ID="Label1" runat="server" Text="Coeus Request ID: " EnableTheming="False"></asp:Literal></b>
</td>
<td>
<asp:TextBox ID="tbRequestId" runat="server" EnableTheming="false" Width="260px"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" OnClientClick="CheckLock();"
CausesValidation="False" UseSubmitBehavior="false" />
</td>
<td>
<asp:Label ID="lblStatus" runat="server" Text="" EnableTheming="False" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>

Another way to update listbox values in listview

I have a ListBox within a ListView that is populated by a SqlDataSource. This ListBox is in the InsertItemTemplate of my ListView.
Is there a way to select a value in the ListBox, click the update button and bring up a TextBox with the selected value so that the user can change the information to save and update? I was thinking if there is a way to bring up a popup window or TextBox that shows the selected value so I can update it.
<asp:ListView ID="FormSectionListView" runat="server" InsertItemPosition="FirstItem">
//omitted other templates because I am not using them.
<InsertItemTemplate>
<tr style="">
<td>
<div style="font-size: .8em; display: block">
<asp:FormView ID="FormSectionFormView" runat="server" DataKeyNames="FormSectionID" DataSourceID="FormSectionDataSource" RowStyle-VerticalAlign="NotSet">
<ItemTemplate>
<tr>
<td>
<asp:Button ID="InsertButton"
runat="server"
Text="Insert"
OnClick="FormSectionButton_Click"
Font-Size="1.2em" />
<asp:Button ID="UpdateButton"
runat="server"
Text="Update"
Font-Size="1.2em"/>
</td>
<td align="center">
<div style: align="center">
<asp:Label ID="Label1"
runat="server"
Font-Bold="true"
Text="Section Instruction"
Font-Size="1.2em">
</asp:Label>
</div>
<div style="width:800px; height:auto; overflow:auto">
<asp:ListBox ID="SectionInstructionListBox"
DataSourceID="SectionInstructionSource"
runat="server"
DataTextField="Instruction"
Visible="True" />
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<div style="padding-top: 4em; width:800px">
<asp:Label ID="Label5"
runat="server"
Font-Bold="true"
Text="Insert New Instruction"
Font-Size="1.2em">
</asp:Label>
<asp:TextBox ID="SectionInstructionTextBox"
runat="server"
Width="800px" />
</div>
</td>
</tr>
</ItemTemplate>
</asp:FormView>
</div>
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>

ListView not updating after selecting value from DropDownlist

For a exercise at school i need to make a website that fetches rows from a SQL-database after selecting a type ( in my case bikes ). I've got most of it working except for the ListView, it won't update when i select a option in the dropdownlist. I think it is a SQL Stored Procedure error but i can't seem to find the problem.
Stored Procedures;
To fetch the types from the db that need to be shown in the dropdownlist (this works)
CREATE PROCEDURE [dbo].[Procedure2]
AS
select a_type
from Artikelen
group by a_type
order by a_type
RETURN
This one is to fetch the rows that have the type the user has selected from the dropdownlist. #type should be the selected value in the dropdownlist.
CREATE PROCEDURE [dbo].[OphaalFietsBijType]
#type varchar(50)
AS
select artikelnr, a_omschr, a_prijs
from Artikelen
where a_type = #type
RETURN
ASP.NET Code
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="A_type" DataValueField="A_type">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="Procedure2" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="artikelnr" DataSourceID="Ophalen">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="artikelnrLabel" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:Label ID="a_omschrLabel" runat="server" Text='<%# Eval("a_omschr") %>' />
</td>
<td>
<asp:Label ID="a_prijsLabel" runat="server" Text='<%# Eval("a_prijs") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="artikelnrLabel1" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:TextBox ID="a_omschrTextBox" runat="server" Text='<%# Bind("a_omschr") %>' />
</td>
<td>
<asp:TextBox ID="a_prijsTextBox" runat="server" Text='<%# Bind("a_prijs") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="artikelnrTextBox" runat="server" Text='<%# Bind("artikelnr") %>' />
</td>
<td>
<asp:TextBox ID="a_omschrTextBox" runat="server" Text='<%# Bind("a_omschr") %>' />
</td>
<td>
<asp:TextBox ID="a_prijsTextBox" runat="server" Text='<%# Bind("a_prijs") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="artikelnrLabel" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:Label ID="a_omschrLabel" runat="server" Text='<%# Eval("a_omschr") %>' />
</td>
<td>
<asp:Label ID="a_prijsLabel" runat="server" Text='<%# Eval("a_prijs") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">artikelnr</th>
<th runat="server">a_omschr</th>
<th runat="server">a_prijs</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="artikelnrLabel" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:Label ID="a_omschrLabel" runat="server" Text='<%# Eval("a_omschr") %>' />
</td>
<td>
<asp:Label ID="a_prijsLabel" runat="server" Text='<%# Eval("a_prijs") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="Ophalen" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="OphaalFietsBijType" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="type" SessionField="#type" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
You are using a SessionParameter but are not setting the session variable anywhere. You also don't need to, since you are getting the value, without any need for complex logic, directly from your DropDownList. What you are after is ControlParameter.
Simply change your parameter to the following:
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="type" Type="String" />

LinqDataSource WhereParameters with a dropdownlist and a field from the database

I will like to perform a LINQ Listview where clause with two items for the where clause: the first one is coming from the Dropdownlist selection (this work fine). I want to add another selection from the a table field from my database (isAvailable). Can you explain me how to populate the request for the where clause using the table field isAvaiable (bool type). I am doing this in C#. Here is the code:
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="ApointmentDataContext"
EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntityTypeName=""
TableName="RendezVous" AutoGenerateWhereClause="True">
<WhereParameters>
<asp:ControlParameter
Name="DoctorName"
ControlID="DropDownList1"
PropertyName="SelectedValue"
Type="String" />
</WhereParameters>
</asp:LinqDataSource>
<div class="center">
<asp:Label ID="lblDoctor" runat="server" Text="Choose a name"> </asp:Label>
<div class="value-right">
<asp:DropDownList ID="DropDownList1" runat="server" Width="180px" AutoPostBack="true" >
<asp:ListItem Text="Doct A" Value="Doc A" />
<asp:ListItem Text="Doct B" Value="Doc B" />
<asp:ListItem Text="Doct C" Value="Doc C" />
</asp:DropDownList>
</div>
</div>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">DoctName</th>
<th runat="server">date</th>
<th runat="server">hour</th>
<th runat="server">patientName</th>
<th runat="server">isAvailable</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="lblDoctorName" runat="server" Text='<%#
Eval("DoctorName") %>' />
</td>
<td>
<asp:Label ID="lblDate" runat="server" Text='<%# Eval("date") %>' />
</td>
<td>
<asp:Label ID="lblhour" runat="server" Text='<%# Eval("hour") %>' />
</td>
<td>
<asp:Label ID="lblPatient" runat="server" Text='<%# Eval("patientName") %>'
/>
</td>
<td>
<asp:Label ID="isAvailable" runat="server" Text='<%# Eval("isAvailable") %>'
/>
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
I need to put the field isAvailable inside of the where clause, can figure it out. Thanks

Keep page position on postback

I have a problem:
<asp:Label ID="Label1" runat="server" Text="Name" CssClass="left"></asp:Label>
<asp:LinkButton ID="LinkEdit" runat="server" CssClass="right_bottom"
onclick="LinkEdit_Click" Height="16px">edit</asp:LinkButton>
<asp:LinkButton ID="Linkhide" runat="server" CssClass="right_bottom"
onclick="Linkhide_Click" Visible="False" hide</asp:LinkButton>
<br />
<hr style="width: 740px; height: -6px; margin-left: 0px; " />
<asp:Label ID="labelFullname" runat="server" Text="Full Name" CssClass="left_top"></asp:Label>
<asp:Label ID="labelNameDisplay" runat="server" Text="Put name here" CssClass="right_top"></asp:Label>
<br />
<asp:Panel ID="panelName" runat="server" Height="240px" Visible="False" CssClass="panel_top"
style="text-align: left;">
<asp:Label ID="Label8" runat="server" CssClass="left" Text="Please allow 24 hours for name changes to take effect."></asp:Label>
<div align="center"><br />
<br />
<table>
<tr>
<td class="label_new">
<asp:Label ID="Label4" runat="server" Text="Full Name:" ToolTip="Name Displayed"></asp:Label>
</td>
<td align="left">
<asp:DropDownList ID="DropDownList1" runat="server" BorderStyle="Groove"
Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="25px"
valign="middle" Width="250px">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label2" runat="server" Text="First Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtFirstName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label9" runat="server" Text="Middle Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtMiddleName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px" onfocus="if (this.value == 'optional') { this.value=''; this.style.color='black';}" />
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label10" runat="server" Text="Last Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtLastName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSaveChanges" runat="server" Text="Save Changes"
onclick="btnSaveChanges_Click" />
</td>
</tr>
</table>
</div>
</asp:Panel>
I have 4 panels in this format just like ACCOUNT SETTINGS on facebook.
My problem here is when I show the panel it just jump to the top of the page.
I would like to do it just as the way facebook is doing. Click and be on at the same position of where you clicked.
You can set the MaintainScrollPositionOnPostback property on your page:
Page.MaintainScrollPositionOnPostback = true;
or put it in the page declaration
<%# Page MaintainScrollPositionOnPostback="true" %>
I'm not entirely sure I what you are asking for. Facebook uses a lot of ajax style callbacks which means that the page doesn't reload using asp .net style postbacks. If you're just starting out I'd recommend you trying placing your code into an Ajax .Net UpdatePanel whilst you learn the details of Ajax / JSON / XMLHttpRequest etc.
If you're simply looking to make sure the browser window remains at the same scrollbar position after a postback then set the page to use the MaintainScrollPositionOnPostback="true" directive.

Categories

Resources