ラベル bind の投稿を表示しています。 すべての投稿を表示
ラベル bind の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Resortlist doesnt update datasource

Hi,

I have a problem with resortlist that makes me mad :-)

I want to bind an ObjectDataSource or a SQLDataSource to a reorderlist, which both works fine when loading data into a itemlist. I can drag and drop all items - but whatever I do, the changed position of my list items won't be saved, neither to the ODS nor the SQLDatasource. Btw: Actually I use the Control Toolkit released mid December and AJAX RC 1. Any idea what's going wrong?


1 <asp:SqlDataSource ID="SQLDataSource1" runat="server"2 ConnectionString="(...)"3 SelectCommand="SELECT [ID], [Name1], [Name2], [order] FROM [tbl_orderlist]"4 UpdateCommand="UPDATE [tbl_orderlist] SET [order]=@dotnet.itags.org.order WHERE [ID]=@dotnet.itags.org.ID">5 <UpdateParameters>6 <asp:Parameter Name="ID" Type=int32 />7 <asp:Parameter Name="order" Type="int32" />8 </UpdateParameters>9 </asp:SqlDataSource>1011 <ajaxToolkit:ReorderList ID="ReorderList1" runat="server"12 DataSourceID="SQLDataSource1"13 ShowInsertItem="true"14 LayoutType="Table"15 DragHandleAlignment="Left"16 DataKeyField="ID"17 AllowReorder="true"18 SortOrderField="order"19 PostBackOnReorder="true"20 CssClass="keyword" >2122 <DragHandleTemplate>23 <div class="dragHandle">24 <table border="0" cellspacing="0" cellpadding="0">25 <tr>26 <td valign="top" class="moveitem"><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name1")%>' /></td>27 <td valign="top" class="moveitem"><asp:Label ID="Label2" runat="server" Text='<%# Eval("Name2")%>' /></td>28 </tr>29 </table>30 </div>31 </DragHandleTemplate>32 </ajaxToolkit:ReorderList>

Thanx a lot for every hint!Smile

Join the club...

I'm fighting the same battle, and it's driving me nuts! The update command simply refuses to fire. I had it working, and now it doesn't work. I just can't seem to get the event to fire.

What happens when you set PostBackOnReorder="false"?


I'm experiencing the same problem! And have no idea what to do... Could anyone from Microsoft Team comment this situation?

Any ideas??


Same problem here!!!! It seems like a bug inside the Reorderlist. Any help here?

Try this site:http://www.codeplex.com/AtlasControlToolkit

In my case, I put a TextBox inside <EditItemTemplate> and binded it to the column in the DB that needs to be updated when reordering:

<EditItemTemplate> <asp:TextBox ID="txtItemOrder" runat="server" Text='<%# Bind("ItemOrder")%>' /></EditItemTemplate>

has anyone figured this out yet?!?!? and does anyone know where I can download the actual code from the AJAX sample website so I can have a look at how MS implemented this?
Driving me crazy!!!


Could you please post the code that actually handles the updateproces for you? So the code-behind method and your datasource/reorderlist definition?

Thanks ahead!


I basically just copied the actual code from the AJAX sample website and tweaked that. I also didn't use any code-behind to handle the reordering. Here's the code:

1<asp:UpdatePanel ID="up1" runat="server">2 <ContentTemplate>3 <div class="reorderListDemo">4 <ajaxToolkit:ReorderList ID="ReorderList1" runat="server" Width="780px" PostBackOnReorder="true"5 DataSourceID="ReorderDataSource" CallbackCssStyle="callbackStyle" DragHandleAlignment="Left"6 ItemInsertLocation="Beginning" DataKeyField="Item_ID" SortOrderField="ItemOrder" CssClass="reorderList">7 <ItemTemplate>8 <div class="itemArea">9 <asp:Label ID="lblItemOrder" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("ItemOrder")))%>' />10 <asp:Label ID="lblName1" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Name1", " - {0}")))%>' />11 <asp:Label ID="lblName2" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Name2", " - {0}")))%>' />12 </div>13 </ItemTemplate>14 <EditItemTemplate>15 <div class="itemArea">16 <asp:TextBox ID="txtItemOrder" runat="server" Text='<%# Bind("ItemOrder")%>' ValidationGroup="edit" />17 </div>18 </EditItemTemplate>19 <ReorderTemplate>20 <asp:Panel ID="Panel2" runat="server" CssClass="reorderCue" />21 </ReorderTemplate>22 <DragHandleTemplate>23 <div class="dragHandle"></div>24 </DragHandleTemplate>25 </ajaxToolkit:ReorderList>26 </div>27 </ContentTemplate>28</asp:UpdatePanel>2930<asp:SqlDataSource ID="ReorderDataSource" runat="server" ConnectionString="<%$ ...%>"31 SelectCommand="SELECT [Item_ID], [Name1], [Name2], [ItemOrder] FROM [Table1]"32 UpdateCommand="UPDATE [Table1] SET [ItemOrder]=@.ItemOrder WHERE Item_ID=@.Item_ID">33 <UpdateParameters>34 <asp:Parameter Name="ItemOrder" Type="Int32" />35 </UpdateParameters>36</asp:SqlDataSource>37

hmm..in your updatecommand you use the parameter @.item_ID...wherefrom is this retreived?

Also, when you reorder items shouldnt there always be 2 items updated? if item 1 goes to index 2, item 2 should go to index 1 right? I dont see how that happens here...

Help is appreciated!

Ok, I now have this, but its still not working...what am I missing here?

<cc1:ReorderList PostBackOnReorder="true"
SortOrderField="RuleIndex"
ID="rolRules"
AllowReorder="true"
DataKeyField="RuleID"
DataSourceID="ReorderDataSource"
runat="server">
<ItemTemplate>
<%#Eval("RuleIndex")%>
<%#Eval("RuleName")%>
</ItemTemplate>
</cc1:ReorderList>

<asp:SqlDataSource ID="ReorderDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SQLAuth %>"
SelectCommand="SELECT RuleID,RuleName,ruleindex FROM myRules WHERE UserCode=@.UserCode"
UpdateCommand="UPDATE myRules SET RuleIndex=@.RuleIndex WHERE RuleID=@.RuleID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="id" Name="UserCode" Type="int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="RuleIndex" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>


myRules table structure:
RuleID int
RuleName nvarchar(20)
ruleindex tinyint
<and some other fields
Thanks!


Peter Smith:

hmm..in your updatecommand you use the parameter @.item_ID...wherefrom is this retreived?

That Item_ID is referenced by the DataKeyField property of the ReorderList (similar with GridView), retrieved from the SELECT command in the DataSource.

Peter Smith:

Also, when you reorder items shouldnt there always be 2 items updated? if item 1 goes to index 2, item 2 should go to index 1 right? I dont see how that happens here...

Help is appreciated!

Well, I guess that's the beauty of the ReorderList control - it does the dirty work for us. As long as we declare which field from the SELECT command is the identity column, and the field that needs resorting... the control handles the rest. We'd have to look at the source code of ReorderList control in order to truly understand the inner workings of how it keeps track of which index should go to another index (etc).Smile But my guess is that, this is done using ViewState to "remember" the values (Identity column, and ItemOrder), and through Javascript's mouse event handlers which triggers the saving of the values to executing the UPDATE command in the DataSource. This is just my personal idea.

I am using AJAX Control Toolkit release 10301 (2007-03-01) and it worked for me using the code I posted here.(Quick note: I experimented with ReorderList again, and found out that using <EditItemTemplate> is not necessary to make the reordering mechanism work; so what I initially said in my first post in this thread doesn't apply anymore).

Best regards!


Peter Smith:

Ok, I now have this, but its still not working...what am I missing here?

Peter,

at first glance, your code looks fine. However, what caught my attention is the "cc1:" tag prefix for the ReorderList control. If the latest version of the AJAX Control Toolkit is correctly installed and registered, the tag prefix should normally be "ajaxToolkit:". So, you might first verify your correct installation of the CT.


che_rish:


Peter Smith:

Also, when you reorder items shouldnt there always be 2 items updated? if item 1 goes to index 2, item 2 should go to index 1 right? I dont see how that happens here...

Well, I guess that's the beauty of the ReorderList control - it does the dirty work for us. As long as we declare which field from the SELECT command is the identity column, and the field that needs resorting... the control handles the rest.

Just in addition to che_rish's excellent explanation: Note that it's not just about swappingtwo ItemOrder values... :) Actually, dragging an item to a different position can comprise as much as updating the ItemOrder fields ofevery single row in the list (for example, when dragging the last item to the first position. And yes, it's all done in the client-side JavaScript that comes with the ReorderList control.Smile


I also used same coding like u. I am also facing same problem.. If any resolves this just let me know.. Thank U.

2012年3月26日月曜日

Return a DataTable with Webservice and Bind via JavaScript

I am using a Webserivce method that returns a DataTable and in JavaScript I have this:

function pageLoad() {
ret = Dashboard.FetchQuadOne(OnCompleteOne, OnTimeOut, OnError);
ret = Dashboard.FetchQuadTwo(OnCompleteTwo, OnTimeOut, OnError);
}

function OnCompleteOne(result) {
document.getElementById('div1').innerHTML = result;
}

If I have my Webservice method, FetchQuadOne return a DataTable, how can I bind that to a GridView using JavaScript? Or is there a way to do this in the code-behind of my .aspx page? I guess I could just build an html table in my webservice method and return that, but it would be mugh each easier to bind the DataTable to a GridView.

I don't see how this could work, a DataTable is a .NET specific object. Javascript has no knowledge of how to consume that or for that matter any knowledge of how to bind to a .NET Datagrid. You could return xml or JSON and bind to some other data structure using XSL or roll your own.

Yeah, that is what I was afraid of. I thought maybe there would be someone way to put the JavaScript in the code-behind page and somehow bind the DataTable to a GirdView. I wanted all the built-in features of the GridView, like sorting and formating. O- well. I just wanted to make sure it wasn't possible before I head down an ugly road of building the table on the fly with the data.

Thanks.


Hi,

I think this article ofKazi Manzur Rashid can help you:http://dotnetslackers.com/articles/ajax/ASPNETAjaxGridAndPager.aspx

This article will show you how to create an AJAX Grid and a generic pager, which mimics the built-in GridView control on the client side.

Best Regards,

2012年3月24日土曜日

Returning a dataset from a web service

Say I have a page that calls a web service from a client function to get some data to bind a gridView like this:

-------------------

<scripttype="text/javascript"language="JavaScript">

function GetDataSet(){

var ds = SimpleService.ActiveProcess();

}

</script >

-------------------

And the web service looks something like this:

-------------------

[WebMethod]

public datasetActiveProcess(){

string connectionString ="Connstring stuff here";

DataSet ds = csql.GetActiveProcess(connectionString);

return ds;

}

-------------------

Of course, because I'm posting this problem, this isn't the correct way to implement this kind of solution...

Question is: Is there a better way? Or how do I manage to handle and display what's being returned from this web service in the web page?

thanks.

doug

This issue is associated with an Atlas Web Service call.

Here is a crude solution that I still need to refine:

------------------------

1. JavasScript call to webservice:

------------------------

function fnSetTimeout( ){

//this is the call to the web service.

var ds = SimpleService.ActiveProcess(OnComplete, OnTimeout);

}

------------------------

2. Webservice method

------------------------

[WebMethod]

publicstring ActiveProcess(){

string connectionString ="Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=simple2;Data Source=local

string xmlReader = csql.GetActiveProcess(connectionString);

return xmlReader;

}

------------------------

3 Webservice method

------------------------

publicstring GetActiveProcess(string connString)

{

string strSQL ="Select id, threadid, conversationId from ActiveProcess";

SqlConnection conn =newSqlConnection(connString);

SqlDataAdapter da =newSqlDataAdapter(strSQL, conn);

DataSet ds =newDataSet();

try

{

conn.Open();

da.Fill(ds);

XmlDataDocument xmlDataDocument =newXmlDataDocument(ds);

return xmlDataDocument.OuterXml.ToString();

}

catch (SqlException ex)

{

returnnull;

}

}

------------------------

3 Load the XML into parser

------------------------

/*==============================================================================

function: OnComplete

paramaters: result

Purpose: Gets the results from the ATLAS call and parses into an XML document

Date: 12/21/2005

==============================================================================*/

function OnComplete(result)

{

//Load XML

var XMLDoc =new ActiveXObject("Microsoft.XMLDOM");

try

{

XMLDoc.loadXML(result);

}

catch(err)

{

alert(err.description);

}

//Load XSL

var XSLDoc =new ActiveXObject("Microsoft.XMLDOM");

try

{

XSLDoc.async =false;

XSLDoc.load("ActiveRecords.xsl");

}

catch(err)

{

alert(err.description);

}

//Write the results of the transformation out to the div.

document.all.divTable.innerHTML = XMLDoc.transformNode(XSLDoc);

}

Here's the XSL if you're interested:

<?xmlversion="1.0"encoding="utf-8"?>

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:templatematch="/">

<html>

<head>

<title>Active</title>

<style>

copy { font-family: Arial, Verdana;}

h1 { font-family: Arial, Verdana; font-size: 14pt;}

p { font-family: Arial, Verdana; font-size: 10pt;}

</style>

</head>

<body>

<p><fontface="verdana">Active</font></p>

<tableborder="1">

<tr>

<thclass="copy">ID</th>

<thclass="copy">Thread Id</th>

<thclass="copy">Configuration ID</th>

</tr>

<xsl:for-eachselect ="NewDataSet/Table">

<tr>

<td>

<xsl:value-ofselect="id"/>

</td>

<td>

<xsl:value-ofselect="threadid"/>

</td>

<td>

<xsl:value-ofselect="conversationId"/>

</td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

thanks...