hyperlink should come in multiline code not working - asp.net

i use this code .. but when the hyperlinks are longer then field size the gridview expands verticaly. i want the link below as like a paragraph . give me a solution
<asp:gridview id="titlesGrid" runat="server"
datasourceid="titles"
width=90% cellpadding=5 font-size="8pt"
autogeneratecolumns=false
headerstyle-backcolor="maroon"
headerstyle-forecolor="khaki"
headerstyle-font-bold
rowstyle-verticalalign="top">
<columns>
<asp:hyperlinkfield headertext="Title"
datatextfield="title"
datanavigateurlformatstring="title_details.aspx?titleid={0}"
datanavigateurlfields="title_id" />
<asp:boundfield headertext="Title ID"
datafield="title_id" />
<asp:boundfield headertext="Category"
datafield="type" />
<asp:boundfield headertext="Pub ID"
datafield="pub_id" />
<asp:boundfield headertext="Price"
datafield="price"
htmlencode=false
dataformatstring="{0:n2}"
itemstyle-horizontalalign="right" />
</columns>
</asp:gridview>

Have you tried using <ItemStyle Wrap="True" /> for <asp:hyperlinkfield /> ?

Related

How to Display 7 days of the week in Gridview Header from a Calendar

I am trying to display the 7 days of the week inside GridView header so my code below shows how to get those days but I don't know how to put them in Gridview Header
with day of names of the week. About like image shows. I run ASP.NET with SQL SERVER EXPRESS database use sqldatasource connection to select all employees to a gridview.
foreach (DateTime selectedDateTime in Calendar1.SelectedDates)
{
Response.Write(selectedDateTime.ToShortDateString() + " <br/>");
}
You can create the columns in the GridView this way:
<asp:GridView ID="GridView1" runat="server" ShowHeader="true" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Monday" HeaderText="Monday" />
<asp:BoundField DataField="Thuesday" HeaderText="Thuesday" />
<asp:BoundField DataField="Wednesday" HeaderText="Wednesday" />
<asp:BoundField DataField="Thursday" HeaderText="Thursday" />
<asp:BoundField DataField="Friday" HeaderText="Friday" />
<asp:BoundField DataField="Saturday" HeaderText="Saturday" />
<asp:BoundField DataField="Sunday" HeaderText="Sunday" />
</Columns>
</asp:GridView>
If no data is expected in the days of the week columns, you could use TemplateFields:
<asp:GridView ID="GridView1" runat="server" ShowHeader="true" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:TemplateField HeaderText="Monday" />
<asp:TemplateField HeaderText="Thuesday" />
<asp:TemplateField HeaderText="Wednesday" />
<asp:TemplateField HeaderText="Thursday" />
<asp:TemplateField HeaderText="Friday" />
<asp:TemplateField HeaderText="Saturday" />
<asp:TemplateField HeaderText="Sunday" />
</Columns>
</asp:GridView>

Display a button in gridview

I have a grid view which display records by reading the data from a local database. I want to display a button called view with each record displayed. Simply meaning in each row there should be an asp.net button called view Details.
Here is my grid view code:
<asp:GridView ID="ItemView" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CssClass="list" DataKeyNames="ItemID"
DataSourceID="ADDataSource" GridLines="Both" Width="215px">
<Columns>
<asp:BoundField DataField="itemID" HeaderText="Item ID" />
<asp:BoundField DataField="Item Name" HeaderText="Item Name" />
<asp:BoundField DataField="Item Brand" HeaderText="Item Brand" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
I have added a button to delete records and edit records through common field property, but how do i add my own button called view to display in each row as the other 2 buttons.
Thank you.
I managed do it myself.
<asp:BoundField DataField="topic" HeaderText="Topic Name" />
<asp:BoundField DataField="Brand" HeaderText="Vehicle Brand" />
<asp:BoundField DataField="Model" HeaderText="Vehicle Model" />
<asp:BoundField DataField="Year" HeaderText="Vehicle Year" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="viewDetails" runat="server" Text="View" />
</ItemTemplate>
</asp:TemplateField>

asp:DetailsView shows one object per page can show multiple

I have the bottom Details view and it shows one detail on a single row is there any there any method that i could use do that i can show multiple detail view objects
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
AutoGenerateRows="False" EnableViewState="False"
DataKeyNames="questionID" DataSourceID="AllQuestions" AllowPaging="True">
<Fields>
<asp:BoundField DataField="SubjectName" HeaderText="SubjectName"
SortExpression="SubjectName" />
<asp:BoundField DataField="Chapter" HeaderText="Chapter"
SortExpression="Chapter" />
<asp:BoundField DataField="Section" HeaderText="Section"
SortExpression="Section" />
<asp:BoundField DataField="questionID" HeaderText="questionID"
InsertVisible="False" ReadOnly="True" SortExpression="questionID" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="sectionID" HeaderText="sectionID"
SortExpression="sectionID" />
<asp:BoundField DataField="QuestionNo" HeaderText="QuestionNo"
SortExpression="QuestionNo" />
<asp:BoundField DataField="question" HeaderText="question"
SortExpression="question" />
<asp:BoundField DataField="A" HeaderText="A" SortExpression="A" />
<asp:BoundField DataField="B" HeaderText="B" SortExpression="B" />
<asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
<asp:BoundField DataField="D" HeaderText="D" SortExpression="D" />
<asp:BoundField DataField="correctAnswer" HeaderText="correctAnswer"
SortExpression="correctAnswer" />
<asp:BoundField DataField="explanation" HeaderText="explanation"
SortExpression="explanation" />
</Fields>
</asp:DetailsView>
Not that I know of.... DetailsView is meant for a single record. Use a GridView or Repeater or ListView for multiple records.

How to display a message when GridView isn't populated

I'm building a GridView based on what is passed on the previous page querystring.
Is there a way to display a message saying 'no records found' if the GridView isn't populated? i.e. the query produces no records to populate the GridView.
code:
<div class="centergrid">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CssClass="bookgridview">
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/bookingform.aspx?ID={0}", Eval("ScheduleId")) %>'>Book</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TName" HeaderText="Name" SortExpression="TName" />
<asp:BoundField DataField="SDate" HeaderText="Date" SortExpression="SDate" DataFormatString="{0:d}" />
<asp:BoundField DataField="STime" HeaderText="Time" SortExpression="STime" />
<asp:BoundField DataField="TPriceadult" HeaderText="Price (Adult)"
SortExpression="TPriceadult" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricesenior" HeaderText="Price (Student/Senior)"
SortExpression="TPricesenior" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricechild" HeaderText="Price (Child)"
SortExpression="Tpricechild" DataFormatString="{0:C}" />
<asp:BoundField DataField="TDuration" HeaderText="Duration"
SortExpression="TDuration" />
<asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId"
SortExpression="ScheduleId" Visible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ChinatowndbConnString %>"
SelectCommand="SELECT * FROM [vwSchedule] Where TourId=#tid">
<SelectParameters>
<asp:QueryStringParameter DbType="Int32" Name="tid" QueryStringField="tourid" />
</SelectParameters>
</asp:SqlDataSource>
Is there a way to display a message saying 'no records found' if the
GridView isn't populated?
Yes, with the EmptyDataTemplate.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CssClass="bookgridview">
<emptydatarowstyle backcolor="LightBlue"
forecolor="Red"/>
<emptydatatemplate>
<asp:image id="NoDataImage"
imageurl="~/images/Image.jpg"
alternatetext="No Image"
runat="server"/>
No records found.
</emptydatatemplate>
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/bookingform.aspx?ID={0}", Eval("ScheduleId")) %>'>Book</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TName" HeaderText="Name" SortExpression="TName" />
<asp:BoundField DataField="SDate" HeaderText="Date" SortExpression="SDate" DataFormatString="{0:d}" />
<asp:BoundField DataField="STime" HeaderText="Time" SortExpression="STime" />
<asp:BoundField DataField="TPriceadult" HeaderText="Price (Adult)"
SortExpression="TPriceadult" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricesenior" HeaderText="Price (Student/Senior)"
SortExpression="TPricesenior" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricechild" HeaderText="Price (Child)"
SortExpression="Tpricechild" DataFormatString="{0:C}" />
<asp:BoundField DataField="TDuration" HeaderText="Duration"
SortExpression="TDuration" />
<asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId"
SortExpression="ScheduleId" Visible="False" />
</Columns>
</asp:GridView>
Alternatively, you can use the built-in UI for the empty data row by setting the EmptyDataText property instead of this property.

Help with ASP.NET ObjectDataSource

I have a User object with a Load method that takes in a UserId parameter and loads that users data to the objects member variables.
Now what I'd like to do is load this data to a DetailsView control using an ObjectDataSource, but I'm stumped as to how.
First of all, I'm not sure I've got the code set up properly to pass the parameter (UserID) to the SelectMethod (cUser.Load). Secondly, I don't know how I can load this data to the DetailsView since I'm not actually returning the results from the Load method, I'm simply loading the object with the data...here's my code..
<asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee" Width="85%"
HorizontalAlign="Center"
Font-Bold="True" Font-Names="Verdana"
Font-Size="10pt" AutoGenerateColumns="False"
OnRowDataBound="GridView1_RowDataBound"
OnRowDeleting="GridView1_RowDeleting"
OnSelectedIndexChanged="IndexChanged" >
<HeaderStyle BackColor="Black" ForeColor="White"
Font-Bold="True" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="yellow" ForeColor="blue" />
<AlternatingRowStyle BackColor="#ffffff" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Select" runat="server">
Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView><br /><br />
<asp:DetailsView runat="server" ID="dvUser" DataSourceID="ObjectDataSource1" AutoGenerateRows="False" Width="85%"
HorizontalAlign="Center" DataKeyNames="UserID" >
<Fields>
<asp:BoundField DataField="UserID" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Password" HeaderText="Password" />
<asp:BoundField DataField="Birthdate" HeaderText="Birthdate" />
<asp:BoundField DataField="Address" HeaderText="Address" />
<asp:BoundField DataField="Apt" HeaderText="Apt" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Province" HeaderText="Province" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
<asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="ynAdminUser" HeaderText="ynAdminUser" />
<asp:CommandField ShowDeleteButton="False" ShowEditButton="True" ShowInsertButton="True" />
>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="ObjectDataSource1"
runat="server" SelectMethod="Load" TypeName="cUser">
<SelectParameters>
<asp:ControlParameter ControlID="gvUsers" PropertyName="SelectedValue" Name="iUserID" Type="int32" />
</SelectParameters>
</asp:ObjectDataSource>
is there a way to do what I'm trying to achieve? if so, can you please give examples with the explanation?
Very much appreciated. Thanks
you need to check this tutorial for detail help....
Master/Detail Using a Selectable Master GridView with a Details DetailView

Resources