Showing posts with label gridview. Show all posts
Showing posts with label gridview. Show all posts

Wednesday, March 28, 2012

Dynamic Gridview

Hi!

I've got a quetion on dynamic gridview load. In my atlas website project i have a gridview that i want to load dynamically. That is, I don't want to load all the data in my datasource because the web page could charge slowly; so, i want to charge only part of the data as fast as possible then, load the other paghes when the user asks for it. How can I do it? Am I to write a C# class in order to manage the load?

Thanks

hi,

it depends on what level do u want to do this ,at what level is it loading slowly.....1)from the dataserver to the dataobject or 2)the control to the current instance of the page...?


it downloads slowly from the dataserver to the dataobject

where is your select query placed?may be in datasource...... place it in a stored procedure as stored procedures are precompiled..... & call the stored procedure....also set EnablePaging to true of the gridview.


My query select is placed in my datasource and my EnablePaging is set to true

Monday, March 26, 2012

Dyanimc TextBoxWatermark in GridView Pager Template

I have a textbox in my gridview pager template to allow the user to enter a page number to jump to. I would like the watermark to read Page X of Y. I tried to set the watermark text on the GridView_DataBound event, but that doesn't work.

My guess is this occurs because most (if not all) AJAX controls render client scripts durning the preload event and the databound event executes long after the preload. Is this correct? Is this by design? Will AJAX controls always render in the preload event?

Is there a workaround I could use to generate thePage X of Y for the watermark via javascript or something?

Thank you for your assistance

This should work - have a look at the DataBinding.aspx page in the ToolkitTests directory for an example. If you're still stuck, please post a complete, self-contained sample demonstrating the issue. Thanks!

DropshadowExtender disappear on gridview selected index changes

Hello,

I have a gridview inside a panel wich is inside an updatepanel. My problem is when I click on my gridview and I select a row the shado and the rounded corners of the panel around the gridview disappear.

I can see the dropshadowextender, only on the first page load, after it disappears. I can't find any solution to keep the rounded corner and the shadow

Please try your scenario with the recently available61121 release of the Toolkit (and ASP.NET AJAX Beta 2). If the problem persists, then please reply with acomplete, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

Saturday, March 24, 2012

DropdownList Update

Hi,

I have modified the sample program for Data Demo. I've used ASP.NET AJAX....I have a dropdownlist and a gridview inside an updatepanel. Also, im connected thru a objectdatasource. the dropdownlist gets value from objectdatasource1. The value comes from a distinct state from the author table while the gridview is connected to objectdatasource2. The value for objectdatasource2 comes from auther table where state = to the dropdownlist selected value.

Now what i want to achieve is that if i edit the state in the gridview my dropdownlist will be automacatically refresh. I tried adding <asp:AsyncPostBackTriggerControlID="GridView1"EventName="SelectedIndexChanged"/> to the updatepanel. I was able to save the changes but the dropdownlist doesnt.

Thanks

2lits

When both the controls that cause a refresh to the updatepanel are inside it, you can use the ChildrenAsTriggers property of the UpdatePanel. Set it to True, and your Dropdownlist should be re-binding.

Thanks


The ChildrenAsTriggers was already set to true but still my dropdownlist is not re-binding...any other thoughts? thanks!


Is your updateMode on conditional basis?

Thanks


it was set to always.

Thanks


I'd say step one is to remove the UpdatePanel and see if this is working in regular postback mode. If it is, then we need to figure out what's going wrong with your UpdatePanels.

I'd want to see some code at that point... is there just one UpdatePanel on the page? Is the GridView inside it? Is the DropDownList?


Yes There is only one Update Panel. The Gridview , dropdownlist, and the sources are inside it.

here's my code :

<formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/> <divtitle="My First AJAX-Enabled Data Driven Page"><asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"><ContentTemplate> <asp:DropDownListID="DropDownList1"runat="server"DataSourceID="ObjectDataSource1"DataTextField="State"DataValueField="State"AutoPostBack=True></asp:DropDownList><asp:GridViewID="GridView1"runat="server"AllowPaging="True"AutoGenerateColumns="False"DataSourceID="ObjectDataSource2"AllowSorting="True"DataKeyNames="AuthorID"><Columns><asp:CommandFieldShowEditButton="True"ShowSelectButton="True"/><asp:BoundFieldDataField="AuthorID"HeaderText="AuthorID"InsertVisible="False"ReadOnly="True"SortExpression="AuthorID"/><asp:BoundFieldDataField="FirstName"HeaderText="FirstName"SortExpression="FirstName"/><asp:BoundFieldDataField="LastName"HeaderText="LastName"SortExpression="LastName"/><asp:BoundFieldDataField="City"HeaderText="City"SortExpression="City"/><asp:BoundFieldDataField="State"HeaderText="State"SortExpression="State"/><asp:BoundFieldDataField="Zip"HeaderText="Zip"SortExpression="Zip"/><asp:BoundFieldDataField="Phone"HeaderText="Phone"SortExpression="Phone"/></Columns></asp:GridView><br/> <asp:ObjectDataSourceID="ObjectDataSource2"runat="server"OldValuesParameterFormatString="{0}"SelectMethod="GetData"TypeName="DataSet2TableAdapters.SelectAuthorsTableAdapter"UpdateMethod="Update"><SelectParameters><asp:ControlParameterControlID="DropDownList1"Name="State"PropertyName="SelectedValue"Type="String"/></SelectParameters><UpdateParameters><asp:ParameterName="AuthorID"Type="Int32"/><asp:ParameterName="FirstName"Type="String"/><asp:ParameterName="LastName"Type="String"/><asp:ParameterName="City"Type="String"/><asp:ParameterName="State"Type="String"/><asp:ParameterName="Zip"Type="String"/><asp:ParameterName="Phone"Type="String"/></UpdateParameters></asp:ObjectDataSource><asp:ObjectDataSourceID="ObjectDataSource1"runat="server"OldValuesParameterFormatString="original_{0}"SelectMethod="GetDataState"TypeName="DataSet2TableAdapters.StateListTableAdapter"></asp:ObjectDataSource><br/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/><asp:AsyncPostBackTriggerControlID="GridView1"EventName="RowUpdated"/></Triggers></asp:UpdatePanel> </div></form>
The updatemode is set to always. I just test it to conditional.

The updatemode is set to always. I just test it to conditional.

Thanks


And what's supposed to happen to the DropDownList when you edit the GridView?

Did you try removing the UpdatePanel? I have a feeling this isn't working with regular postbacks either and doesn't really have to do with AJAX, since your UpdatePanel code looks correct.


I should be able to see the updates in the state. example if I change the state from MI to NW upon save i should be able to see NW added in the dropdownlist. It is working on the regular postback...

Steve Marx:

I have a feeling this isn't working with regular postbacks either and doesn't really have to do with AJAX, since your UpdatePanel code looks correct.

This is to do with AJAX. When the DropDownList is binded declaratively, the list wont get refreshed on the triggers of the updatepanel. You need to explicitly bind the dropdownlist in the events specified on the updatepanel. But if have you had used the same ObjectSource for both the GridView and DropDownList, then sure the list gets updated.

Since the OP is working on the same database table, one ObjectDataSource is enough and when the GridView UpdateCommand is called, the data for the DropDownList is pulled again.

Thanks


e_screw, I don't quite understand... the databinding should work exactly the same way in a regular postback and an async postback. I'm still having trouble figuring out how this can work without the UpdatePanel but fail with it.

Certainly the DropDownList has to be bound again in the event handler, but what does that have to do with AJAX?


yes..thats also my understanding. How does the updatepanel rebind the data?

Thanks so much!


Steve Marx:

... the databinding should work exactly the same way in a regular postback and an async postback. I'm still having trouble figuring out how this can work without the UpdatePanel but fail with it. Certainly the DropDownList has to be bound again in the event handler, but what does that have to do with AJAX?

I am not sure though (still learning AJAX), the DataBinding of the controls (set declaratively using DataSourceID) will be started before the PreRender event of the page and not sure if the necessary client-scripts for that will be injected into the page by AJAX. I have checked with a different ObjectDataSource (each for Dropdownlist and GridView), and there was no client-script generated for the DropDownList unless there was explicit binding. When you are using the same ObjectDataSource for both the controls, there was client-script inject for both even if there was no explicit binding.

Thanks

Wednesday, March 21, 2012

DropDownExtender in a GridView issues (v1.0 beta)

I am trying to add a DropDownExtender within a GridView control using the code below but it fails i.e. The DropDownExtender is never displayed (no javascript errors). Then if I use the paging in the gridview to navigate to another page and hover over a row it causes a javascript error 'Line 196 Error: Object doesn't support this method or property'.

I've tried this with other controls (e.g. TextboxWatermark) in a GridView and they work ok but are a bit glitchy. Is this a known issue?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="Number,Sequence" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="DropPanel" runat="server" CssClass="ContextMenuPanel" Style='display:none;visibility:hidden;'>
<asp:LinkButton runat="server" ID="Option1" Text="Option 1" CssClass="ContextMenuItem" OnClick="OnSelect" />
<asp:LinkButton runat="server" ID="Option2" Text="Option 2" CssClass="ContextMenuItem" OnClick="OnSelect" />
<asp:LinkButton runat="server" ID="Option3" Text="Option 3 (Click Me!)" CssClass="ContextMenuItem" OnClick="OnSelect" />
</asp:Panel>
<asp:Label ID="TheLabel" runat="server" Text="Howydoing" />
<ajaxToolkit:DropDownExtender ID="DDE" runat="server" DropDownControlID="DropPanel" TargetControlID="TheLabel"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Number" HeaderText="Number" ReadOnly="True" SortExpression="Number" />
<asp:BoundField DataField="Sequence" HeaderText="Sequence" ReadOnly="True" SortExpression="Sequence" />
<asp:BoundField DataField="Reference" HeaderText="Reference" SortExpression="Reference" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>

Javascript where error occurs is: (this is part of the AjaxControlToolkit runtime scripts):

// NOTE: [rb] replaced with CommonToolkitScripts version
// var offsetParentLocation = Sys.UI.DomElement.getLocation(offsetParent);
// var parentBounds = Sys.UI.DomElement.getBounds(parent);
var offsetParentLocation = CommonToolkitScripts.getLocation(offsetParent);
var parentBounds = CommonToolkitScripts.getBounds(parent);

The problem here looks to be an issue with the current beta of ASP.NET AJAX, and I am following up with Shawn Burke and the ASP.NET AJAX team at Microsoft. The issue at hand is that ScriptManager currently emits all of its script for Extenders and ScriptReferences in it's own PreRender event which will happen before the PreRender event of the GridView. In the initial page request (Page.IsPostBack == false), a GridView bound using DataSourceID will delay binding until the last possible moment, which happens to be PreRender.

Until the ASP.NET AJAX team can address this issue, the quickest way to solve the bug is to temporarily add the following code to your Page or UserControl:

1protected void Page_Load(object sender, EventArgs e)2{3if (!Page.IsPostBack)4 {5 Grid.DataBind();6 }7}8 

Where Grid is the name of your DataGrid. This will cause the binding to the DataSourceID to happen in Load as opposed to PreRender.

Try the above and see if it solves your problem. I have another application I am working on that is exhibiting the same issue and this fixed it.


Thanks for that - that solved part of the problem to do with why it wasn't working on the first page display, however I was still getting the Javascript error. After a bit of debugging I found the following error in AjaxControlToolkit\Common\Common.js Line 196, which read:

var mediumThickness = this.parseBorderThickness("medium");

parseBorderThickness doesn't exist. however _borderThicknesses does and has values for thin, medium and thick. So changing the line to read:

var mediumThickness = this._borderThicknesses.medium;

solved the issue, however the DropDown is not quite aligned properly with the text so it looks like there is some additional work required in this area - maybe this will be fixed in the next release.


Thanks for pointing that out, that was a bad reference. The correct function name isparseBorderWidth not parseBorderThickness. I have made the change and checked it in and it should be corrected in the next toolkit release.

Can you provide me with some further details as to the alignment issue, or a sample I might be able to look at (source code/designwise) that I can try to use to figure out what might be causing a problem with the offset?


Source code is below. There are 2 issues:

1) The alignment of the DropDown box when hovering over 'TheLabel' is wrong in IE 6. This is correct when using Firefox 2.0. I am able to resolve this in IE by modifying the Common.js file like so:

if(defaultTdLeftBorderFound) offsetX -= mediumThickness + 4; //(Previously was -1)
if(defaultTdTopBorderFound) offsetY -= mediumThickness + 3; //(Previously was -1)

2) The glitchy behaviour I mentioned earlier seems to be a problem with other controls as well (at least TextBoxWatermark) which occurs when you navigate to the last page in a paged grid. I get a Javascript error in MicrosoftAjax.js: Line 451: Error: '_behaviors' is null or not an object

Default.aspx:
<%@. Page Language="C#" AutoEventWireup="true" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<script runat="server">
protected void Page_Load(Object sender, EventArgs args)
{
if (!Page.IsPostBack)
{
GridView1.DataBind();
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style>
.ContextMenuPanel
{
background-color:white;
border: 1px solid #868686;
z-index: 1000;
cursor: default;
padding: 1px 1px 0px 1px;
font-size: 11px;
}
a.ContextMenuItem
{
display: block;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="Number,Sequence" DataSourceID="XmlDataSource2">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="DropPanel" runat="server" CssClass="ContextMenuPanel" Style='display:none;visibility:hidden;'>
<asp:LinkButton runat="server" ID="Option1" Text="Option 1" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="Option2" Text="Option 2" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="Option3" Text="Option 3 (Click Me!)" CssClass="ContextMenuItem" />
</asp:Panel>
<asp:Label ID="TheLabel" runat="server" Text="Howydoing" />
<ajaxToolkit:DropDownExtender ID="DDE" runat="server" DropDownControlID="DropPanel" TargetControlID="TheLabel"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Number" HeaderText="Number" ReadOnly="True" SortExpression="Number" />
<asp:BoundField DataField="Sequence" HeaderText="Sequence" ReadOnly="True" SortExpression="Sequence" />
<asp:BoundField DataField="Reference" HeaderText="Reference" SortExpression="Reference" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource2" runat="server">
<Data>
<TheData>
<row Number="asdfasdf" Sequence="001" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="002" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="003" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="004" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="005" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="006" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="007" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="008" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="009" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="010" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="011" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="012" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="013" Title="eflwef fwe " Reference="fwefwewefwef"/>
</TheData>
</Data>
</asp:XmlDataSource>
</div>
</form>
</body>
</html>

Notes: Web.config is taken direct from C:\Program Files\MicrosoftASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\web_CTP.config and needsreferences to Microsoft.Web.Preview.dll and AjaxControlToolkit.dll


I've found that using a repeater table works just fine, but I continue to have problems with the GridView.

Suman Chakrabarti [MSFT]


I notive the alignment problem when placed inside a table with a border > 0px . If I set the boder to zero it lines up.
is this fixed in the current downloadable rc1 version?

Hi,

did you solve this problem? I have got the same problem at the moment. Is there a solution available?

--edit--

I just saw, my code is a little bit different

 <asp:HyperLink ID="hl1" runat="Server" NavigateUrl='<%# Eval("Id")%>' OnDataBinding="hl1_DataBinding"><asp:Label ID="TheLabel" runat="server" Text="Howydoing" /></asp:HyperLink>