2010年11月30日星期二

Make Ajax Calls Using jQuery

http://www.asp.net/ajax/videos/how-do-i-make-ajax-calls-using-jquery


In this video Chris Pels shows how to make Ajax calls using the jQuery library. A sample web site is created that contains a simple web service which returns a value. Next, the jQuery ajax() method is used to call the web service. A number of the ajax() method options are set including url, dataType, data, etc. In addition, event handlers for both success and error conditions are defined. Another web services is then defined which accepts an argument and also returns a value. A second ajax() call is defined that passes a value to the web service call and processes the return data. Finally, the setup for global options and event handlers for ajax() method calls are discussed.





Reducing Code by Using jQuery Templates

Reducing Code by Using jQuery Templates
http://weblogs.asp.net/dwahlin/archive/2010/11/20/reducing-code-by-using-jquery-templates.aspx

Not Using jQuery JavaScript Templates? You’re Really Missing Out.
http://blog.reybango.com/2010/07/09/not-using-jquery-javascript-templates-youre-really-missing-out/

Controller and Action in MVC


2010年11月29日星期一

Some code-snippet in GridView, ListView control

Comparing ListView with GridView,DataList and Repeater
http://weblogs.asp.net/anasghanem/archive/2008/09/06/comparing-listview-with-gridview-datalist-and-repeater.aspx

1. ListViewItem listEditItem = lvJournals.Items[lvJournals.EditIndex];

2. protected void odsJournals_Updating(object Sender, ObjectDataSourceMethodEventArgs E)
{
E.InputParameters["JournalId"] = GetCurrentColumnItemId();
E.InputParameters["ModifiedBy"] = LogonUser.FullName;

3. protected override void CurrentFormObjectDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{
if (e.InputParameters[0] != null && e.InputParameters[0].GetType().Equals(typeof(tblRole_NEW)))
{
tblRole_NEW r = (tblRole_NEW)e.InputParameters[0];
r.ApplicationName = SelectedApplicationName;
}
base.CurrentFormObjectDataSource_Inserting(sender, e);
}


4. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim rw As GridViewRow = GridView1.Rows(e.RowIndex)
Dim dt As Data.DataTable = CType(Session("SavData"), Data.DataTable)

Dim prodid As String = CType(rw.Cells(1).Controls(0), TextBox).Text
Dim prodname As String = CType(rw.Cells(2).Controls(0), TextBox).Text
Dim supid As String = CType(rw.Cells(3).Controls(0), TextBox).Text
Dim catid As String = CType(rw.Cells(4).Controls(0), TextBox).Text

Dim old_prodid As String = dt.Rows(e.RowIndex).Item("productid")
Dim old_prodname As String = dt.Rows(e.RowIndex).Item("ProductName")
Dim old_supid As String = dt.Rows(e.RowIndex).Item("SupplierID")
Dim old_catid As String = dt.Rows(e.RowIndex).Item("CategoryID")


5. protected override void CurrentFormObjectDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
if (!DisableGridView && CurrentGrid.SelectedDataKey != null && CurrentGrid.SelectedDataKey["RoleName"] != null && CurrentGrid.SelectedDataKey["ApplicationName"] != null)
{
e.InputParameters["applicationName"] = (string)CurrentGrid.SelectedDataKey["ApplicationName"];
e.InputParameters["roleName"] = (string)CurrentGrid.SelectedDataKey["RoleName"];
}
else
e.Cancel = true;
base.CurrentFormObjectDataSource_Selecting(sender, e);
}


6. string ID = GridView1.DataKeys[e.RowIndex].Value.ToString();

asp:gridview id="CustomersGridView" datakeynames="CustomerID" runat="server">
/asp:gridview>

7. SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />

8. lbDelete.OnClientClick = "javascript:return confirm('" + AppStrings.ctlEventList_DeleteAlert + "');";

9. asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete" CommandArgument='<%# Container.DataItemIndex %>' Text="Delete">

CurrentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
switch (e.CommandName.ToLower())
{
case "select":
CurrentGrid.SelectedIndex = Convert.ToInt32(e.CommandArgument);
...
}

10.
protected virtual void CurrentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
...
GridViewRow row = GetGridViewRow(e.CommandSource as Control);
...
}

protected GridViewRow GetGridViewRow(Control cntr)
{
if (cntr != null)
{
if (cntr.GetType().Equals(typeof(GridViewRow)))
return cntr as GridViewRow;
else
return GetGridViewRow(cntr.Parent);
}

return null;
}

11.
CurrentGridObjectDataSource_Updating
CurrentGridObjectDataSource_Updated
CurrentForm_ItemUpdated

CurrentForm_ModeChanging
CurrentForm_ModeChanged

CurrentGridObjectDataSource_Selecting
CurrentForm_ItemCreated