Use different data forms inside default grid view in asp.net - html

I have the above grid view where I am using the default one provided by Visual Studio. What I am doing is, via the server properties dragging the table and the VS creates the above for me.
However, I want my category 1 and category 2 and category 3 be dropdown lists.
Is there any way to change the default behavior of the grid view?

Use Template Field in the source code inside the grid.
It will look like
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField HeaderText="id" DataField="id" />
<asp:BoundField HeaderText="Name" DataField="name" />
<asp:TemplateField HeaderText = "category1">
<ItemTemplate>
<asp:Label ID="lblcategory1" runat="server" Text='<%# Eval("category1") %>' Visible = "false" />
<asp:DropDownList ID="ddlcategory1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and so on.

Related

How To Display CKEditor Data In Stimulsoft? and In WebForm Grid View?

How To Display CKEditor Data In Stimulsoft? and In WebForm Grid View ?
I Use CkEditor to Save My Data In SQL then Data Saved as HTML Tags In Database
When I want to Display Data In StimulSoft
My data Show As HTML Tag . but I want to Display with out Html Tags.
Well, for the most part, you can directly display such content on a web page.
In most cases, even a simple label dropped onto the form will correctly render that column of data.
Say we have a simple GridView like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID"
CssClass="table table-hover" Width="50%" GridLines="None"
ShowHeaderWhenEmpty="true">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Info">
<ItemTemplate>
<asp:Label ID="lblMarkUp" runat="server" width="340px"
Text='<%# Eval("ImageInfo") %>' >
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="cmdEdit" runat="server" Text="Edit" CssClass="btn myshadow"
OnClick="cmdEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and out code beind to load is this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid()
End If
End Sub
Sub LoadGrid()
Dim strSQL As String = "SELECT * FROM tblHotelsP ORDER BY HotelName"
GridView1.DataSource = Myrst(strSQL)
GridView1.DataBind()
End Sub
So, all we did was shove a data table right into the grid.
However, note that ONE column we have. I don't have ckedit installed, but I do have the ajaxtoolkit HTML editor. The results will be the same. We "save" that one column right into the database.
So, in most cases, any markup, and even ctrl-v to paste in a picture will work.
The results of the above grid are thus this:
A text box will not work, but a label will as per above.
You can also say use a content placeholder or whatever. However, I find just a simple label control works rather well in most cases (as the above example grid using a label shows)

What's the difference in asp tags if we use <asp:BoundField /> or <asp:BoundField> and </asp:BoundField>?

I'm starting to understand ASP code through a complete project written by others. In the aspx file, there is code like
<asp:BoundField DataField="Location" HeaderStyle-HorizontalAlign="Center"
HeaderText="Location" SortExpression="Location">
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
. but if I put
<asp:BoundField DataField="Lcation" HeaderStyle-HorizontalAlign="Center" HeaderText="Location" SortExpression="Location" />
, it's also works. I'm wondering about if there is difference between those ending tags with/without the name of beginning. Thanks!
That's called a self-closing tag.
They're identical.

GridView Centering Issues

How can I center the text of the rows of an <asp:GridView /> that gets populated at run-time?
I have tried RowStyle-HorizontalAlign="Center" and similar things that I have found in this site to no avail.
Similarly, I cannot center a GridView inside a div—that is, <div><asp:GridView /></div>—to save my life.
Am I using a bunch of deprecated functions or what? Also, Chrome is my default browser.
I am aware that a thousand questions in the gist of mine have been asked before, but all that I have tried are either years old or are not working.
Thanks in advance!
Are you using bound columns or autogenerated? If you're binding them in your markup, something like this should work fine (this is an actual example from something of mine):
<asp:TemplateField HeaderText="External Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:TextBox ID="txtExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewExternalId" runat="server" Width="100%" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Delete record from table that has related table

I am working in MS Access and I getting "cannot delete from specified tables" errors.
My tables are:
Orders
OrderDetails
Products
OrderView
OrderView is a query table with data is from OrderDetails and Products tables respectively.
I am trying to delete records from OrderDetails where the productId matches my productId in the a gridview.
My sql statement is:
DELETE * FROM OrderDetails WHERE productId=#productId
I am getting #productId from the grid view
This is my grid view markup:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="row3" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
GridLines="Horizontal"
DataKeyNames="oProductId"
width="100%"
>
<Columns>
<asp:BoundField DataField="oProductId" HeaderText="Product Id"
SortExpression="oProductId" />
<asp:BoundField DataField="pProductName" HeaderText="Product Name"
SortExpression="pProductName" />
<asp:BoundField DataField="oQty" HeaderText="Quantity"
SortExpression="oQty" />
<asp:BoundField DataField="oPrice" HeaderText="Price" SortExpression="oPrice"
DataFormatString="{0:c}" />
<asp:BoundField DataField="oAmt" HeaderText="Amount"
SortExpression="oAmt" ReadOnly="True" DataFormatString="{0:c}" />
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
How many records are in that table? How many records are you trying to delete?
I run into the overflow error when I try to delete more than 30,000 records out of a table containing 1 million + records. This seems to be an Access limitation. Access cannot handle enough memory to hold all records in memory and do a search and delete while keeping the deleted data for the purpose of rolling back in event of error. That's my best guess.
I have tackled this issue using 2 strategies: 1) Do not insert any records into a large table unless absolutely sure I need them inserted right now. Use a temp table or global var array to temporarily store values. 2) Delete in small chunks. E.G. DELETE ... WHERE ID BETWEEN 20000 AND 25000. Make sure the column you name in the WHERE clause is an Indexed column. I include such a statement in a loop, incrementing the 2 vals in the BETWEEN phrase.

Rendering thousands of thumbnails table vs div vs span

My current code using tables to render thumbnails. When the page is resized, I use javascript to recalculate the number of rows and reinsert the cells into the correct columns.
This works fine for 100 thumbnails but is kind of slow when displaying 3000 thumbnails.
So I've looked at how bing displays its thumbnails and it appears to use span tags with display:inline-block. I've tested laying out thumbnails using span tags this has the benefit of automatically wrapping the thumbnails for me when I resize the page. I've also tested using DIV tags with float:left and it appears to be much slower than span on some browsers but not others.
However I'm wondering which method is typically fastest on all browsers for the kind of thumbnail layout i want.
a) Table
b) DIV tags with float:left
c) Span tags with display:inline-block
and in general do DIV tags render slower than span tags?
Of course the div / span solution will always be faster than the table solution because you don´t have to use javascript.
About the difference between span's, div's, floats and inline-blocks: I can´t imagine that there is a difference, but if there is, it will depend on the browser you´re using so you will have to test that in different browsers.
This may not be a direct answer to your question. But I would look at pagination. 3000 is a lot of records for one page. If you paginate (see YUI's carousel) you can reduce it down to 100 thumbnail chunks. Using the YUI pagination you could also allow the user to choose how many to put on one screen. Plus, the pagination does not need to do a server round trip if you don't want it too.
I would think that spans would load quicker but I have little substantial information on which to base this assumption. However, there is an approach you can take, I forget the term, but only content visible on the screen will load. Content that would need scrolling to be visible would not be loaded until it would be visible on the screen. This may help you speed up your loading.
Take a look at this link and it will give a script to do this loading technique: http://www.dynamicdrive.com/forums/showthread.php?p=200232
I created this script as a test:
<html>
<body>
<script type="text/javascript">
var i=0;
var startDate = Date();
for (i=0;i<=3000;i++)
{
document.write("<div style='float: left;display: inline;border: black 1px dotted; width: 100px; height: 100px;'>The number is " + i + "</div>");
}
var endDate = Date();
document.write("<br/>");
document.write("<strong>Started :</strong> " + startDate );
document.write("<br/><br/>");
document.write("<strong>Finished:</strong> " + endDate );
</script>
</body>
</html>
Switching to a span created no noticeable performance difference.
However, I know for a fact that IE has serious problems if you set the background to an image in a table cell or a DIV. It just doesn't render as fast. Not sure if that is how you are inserting the thumbnails.
Guys found some very interesting results. let me know if you can confirm. So I went extreme and tested with binding a 20,000 record xml to an asp.net listview to benchmark. very interesting.
this listview template which uses span
firefox: takes 10 seconds to render and refreshes/wraps immediately as page is resized. uses 367mb of memory
IE 8: takes 20 seconds to render and takes 10 seconds to wrap as page is resized. uses 605mb of memory.
<asp:ListView ID="ListView1" runat="server" DataSourceID="XmlDataSource1" >
<LayoutTemplate>
<div runat="server" id="lstProducts">
<div runat="server" id="itemPlaceholder" />
</div>
</LayoutTemplate>
<ItemTemplate>
<span runat="server" style="display:inline-block">
<asp:Image runat="server" Style="width: 100px" enableviewstate="false" ID="ImageButton1" ImageUrl='<%# Eval("ImageUrl", "~/Photos/{0}") %>' />
<br />
<asp:Label ID="PropertyTypeLabel" runat="server" enableviewstate="false" Text='<%# Eval("PropertyType") %>' />
<br />
Bedrooms:
<asp:Label ID="BedroomsLabel" runat="server" enableviewstate="false" Text='<%# Eval("Bedrooms") %>' />
<br />
Town:
<asp:Label ID="TownLabel" runat="server" enableviewstate="false" Text='<%# Eval("Town") %>' />
<br />
Lat:
<asp:Label ID="LatLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lat") %>' />
<br />
Lon:
<asp:Label ID="LonLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lon") %>' />
<br />
Price:<asp:Label ID="PriceLabel" runat="server" enableviewstate="false" Text='<%# Eval("Price", "£{0}") %>' />
</span>
</ItemTemplate>
</asp:ListView>
this listview template which uses div looks like this
<asp:ListView ID="ListView1" runat="server" DataSourceID="XmlDataSource1" >
<LayoutTemplate>
<div runat="server" id="lstProducts">
<div runat="server" id="itemPlaceholder" />
</div>
</LayoutTemplate>
<ItemTemplate>
<div runat="server" style="float:left">
<asp:Image runat="server" Style="width: 100px" enableviewstate="false" ID="ImageButton1" ImageUrl='<%# Eval("ImageUrl", "~/Photos/{0}") %>' />
<br />
<asp:Label ID="PropertyTypeLabel" runat="server" enableviewstate="false" Text='<%# Eval("PropertyType") %>' />
<br />
Bedrooms:
<asp:Label ID="BedroomsLabel" runat="server" enableviewstate="false" Text='<%# Eval("Bedrooms") %>' />
<br />
Town:
<asp:Label ID="TownLabel" runat="server" enableviewstate="false" Text='<%# Eval("Town") %>' />
<br />
Lat:
<asp:Label ID="LatLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lat") %>' />
<br />
Lon:
<asp:Label ID="LonLabel" runat="server" enableviewstate="false" Text='<%# Eval("Lon") %>' />
<br />
Price:<asp:Label ID="PriceLabel" runat="server" enableviewstate="false" Text='<%# Eval("Price", "£{0}") %>' />
</div>
</ItemTemplate>
</asp:ListView>
firefox: takes > 2 minutes seconds to render and refreshes/wraps take 40 seconds as page is resized. uses 500mb of memory
IE 8: takes 50 seconds to render and takes 20 seconds to wrap as page is resized. uses 600mb of memory.
so it looks like firefox handles rendering thousands of divs much worse than IE. and on both browsers thousands of spans render faster than divs.