GridView Centering Issues - html

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>

Related

ASP.Net TextBox and CTRL+F not working

I'm simply looking for a solution to make a web browsers CTRL+F work with TextBoxes in ASP.Net. This is a web form, though any TextBox I create, renders as an and for some reason, the Text displayed on page can't be searched via a browsers CTRL+F page search feature.
<asp:TextBox ID="txtbxTest" ClientIDMode="Static" runat="server" Width="98%" CssClass="GridViewTextBoxCenteringNoBorder" Text='<%# Bind("TestDBColumn") %>' Tooltip='<%# Bind("TestDBColumn") %>' onchange="javascript: RowTextChanged( this )" ></asp:TextBox>

<a href> tag in TextBox in GridView

This is not a pretty application by any stretch. It's only meant for a select few to use in the office and does not require street appeal. With that said...
I have a gridview with the following template column:
<asp:TemplateField HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblAction" runat="server" Text='<%#(Eval("Action"))%>'
ToolTip="Action to be Taken"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAction" runat="server"
TextMode="MultiLine" Width="450px" Height="100px" ValidationGroup="UpdateFU"
Text='<%#Eval("Action")%>'
CssClass="RequiredText" ToolTip="Follow-Up Action">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_txtAction" runat="server"
ControlToValidate="txtAction" ErrorMessage="FollowUp Action is Required"
Text="*" ValidationGroup="UpdateFU">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAction" runat="server"
TextMode="MultiLine" Width="250px"
ValidationGroup="UpdateFU"
CssClass="RequiredText"
ToolTip="Follow-Up Action">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_txtAction" runat="server"
ControlToValidate="txtAction" ErrorMessage="FollowUp Action is Required"
Text="*" ValidationGroup="AddFU">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
For the example that is causing me trouble, the data in the field that is bound to this column is: **Testing with a link. Google**
The label in the ItemTemplate displays as I expect it to. The regular text is not hyperlinked and the hyperlink text is. Please see the included image:
ItemTemplate
When my row is in Edit mode, it also displays in the TextBox as I would suspect. Please see the included image: EditItemTemplate
When I attempt to Save or Cancel the record, the gridview does not recognize that the command button was clicked. It just sits there. If I remove the text that references the tag (leaving from my example, **Testing with a link.**), it works beautifully. The only problem being that I can't save any text in the textbox with my link.
Any help is greatly appreciated.
I think you are using UpdatePanel around your GridView. That is why you are missing exceptions if you are not checking the browser console. And that exception could very well be A potentially dangerous Request.Form value was detected from the client
Fixes for that here
A potentially dangerous Request.Form value was detected from the client
A potentially dangerous Request.Form value was detected from the client
https://www.codeproject.com/Tips/297679/A-potentially-dangerous-Request-Form-value-was-det
https://www.aspsnippets.com/Articles/ASPNet-Error-A-potentially-dangerous-RequestForm-value-was-detected-from-the-client.aspx

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

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.

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.

Ajax:ModalPopup js exception, BackgroundCssClass is null

I use a modal popup extender, i followed all the instructions on the toolkit sample page, except that i didn't set the property BackgroundCssClass.
this is what happens:
Is there a way I can get rude of it without setting the cssclass prop?
I don't need any styles.
If the answer is NO then please show me an example how to set it with a cssclass (even dummy).
Thanks in advance.
Here is the code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<div style="size: 100%; vertical-align: middle">
<asp:LinkButton ID="lnkUpload" Text="Upload" ToolTip="Upload new file" runat="server" OnClick="lnkUpload_Click" />
<cc1:ModalPopupExtender ID="lnkUpload_ModalPopupExtender" runat="server" Drag="true" PopupDragHandleControlID="pnlUploadTitle" DynamicServicePath="" PopupControlID="pnlUpload" Enabled="True" TargetControlID="lnkUpload" CancelControlID="btnCancel" />
</div>
<asp:Panel ID="pnlUploadTitle" runat="server" Visible="false">
<center>
Upload file
</center>
</asp:Panel>
<asp:Panel ID="pnlUpload" runat="server" Visible="false">
<center>
<br />
<asp:FileUpload ID="upFiles" runat="server" /><br />
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<br />
</center>
</asp:Panel>
</div>
</form>
You can set the ModalPopupExtender's backgroundCssClass within the actual HTML markup.
Example from the asp.net modal popup page:
<ajaxToolkit:ModalPopupExtender ID="MPE" runat="server"
TargetControlID="LinkButton1"
PopupControlID="Panel1"
**BackgroundCssClass="modalBackground"**
DropShadow="true"
OkControlID="OkButton"
OnOkScript="onOk()"
CancelControlID="CancelButton"
PopupDragHandleControlID="Panel3" />
I spent ages looking up a solution for the similar problem
Set your PopUpControlId to be the ClientID of the control.
It solved the problem for me.
Also read more on: Codeplex
Ha-ha, I remember more then 2 years ago in AJAX beta not setting the BackgroundCssClass property caused modal popup not to be really modal, but just popup. I remember setting a style class solved the problem. I haven't used AJAX for a long time, it's funny if similar problems still persist.
Anyway, create stylesheet class inside your ASPX page or in CSS file referenced form it and set the property value to it. Maybe, this will also help.