asp:DetailsView shows one object per page can show multiple - asp.net

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.

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>

hiding a column in asp.net

I want to hide a column in a gridview. I use the following code;
dgvTekleme.Columns[1].Visible = false;
but this does not work. (may be it does not work because of using that column in the code)
Is there any solution to hide a column in code-behind
you can do this manually.....
goto asp:gridview tag and in gridview tag set autogeneratecolumn="false"
if you don't want to display some column just don't write that column....
for example if you don't want to display prodId column just erase that line....
and write manually for displaying data like!!!!!!!!!!
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="ProdID" DataField="prodid" ReadOnly="true" />
<asp:BoundField HeaderText="ProdName" DataField="ProdName" />
<asp:BoundField HeaderText="Quantity" DataField="quantity" />
<asp:BoundField HeaderText="SupplierID" DataField="SupplierId" />
<asp:BoundField HeaderText="StockLvl" DataField="stocklevel" />
<asp:BoundField HeaderText="MinStockLvl" DataField="minstocklevel" />
<asp:BoundField HeaderText="CostPrice" DataField="costprice" />
<asp:BoundField HeaderText="SalesPrice" DataField="saleprice" />
<asp:BoundField HeaderText="Loc" DataField="location" />
<asp:BoundField HeaderText="ProdCode" DataField="prodtypecode" />
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
or you can check this link:
How to hide columns in an ASP.NET GridView with auto-generated columns?

hyperlink should come in multiline code not working

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 /> ?

GridView delete command not firing in server. Locally works

I have this gridview, that works perfectly when running in local computer. Platform is VWD 2010 - Sql Server
<asp:GridView ID="Gv_Usuarios" runat="server"
AutoGenerateColumns="False"
DataKeyNames="Login,ID" DataSourceID="SqlDataSource1" EnableModelValidation="True"
Width="619px">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete" OnClientClick='if
(!confirm("Borra?")) return false;' Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Tipo" HeaderText="Tipo" SortExpression="Tipo" />
<asp:BoundField DataField="Nombre" HeaderText="Nombre" SortExpression="Nombre" />
<asp:BoundField DataField="Login" HeaderText="Login" ReadOnly="True"
SortExpression="Login" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Vendedor" HeaderText="Vendedor"
SortExpression="Vendedor" />
<asp:BoundField DataField="Sucursal" HeaderText="Sucursal"
SortExpression="Sucursal" />
<asp:BoundField DataField="Almacen" HeaderText="Almacen"
SortExpression="Almacen" />
<asp:BoundField DataField="Fecha" HeaderText="Fecha" SortExpression="Fecha" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
</Columns>
</asp:GridView>
Browser fire the confirmation question, but after hittting YES, nothing happens.
It works fine in my computer, nothing happens in the hosting server.
Thanks in advance.
Use asp:Button instead of asp:LinkButton

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