Tuesday, September 20, 2011

Monday, September 12, 2011

Efficient Paging for GridView



REf: http://www.nikhedonia.com/notebook/entry/efficient-paging-for-gridview/

Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it

Excellent reference

1) http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx




Wednesday, September 7, 2011

Modal UpdateProgress for UpdatePanel


ref1: http://mattberseth.com/blog/2007/07/modalpopup_as_an_ajax_progress.html - simple and easy

ref1: http://blogs.visoftinc.com/2008/03/13/Modal-UpdateProgress-for-UpdatePanel-Revisited/ 

ref2:  http://weblogs.asp.net/guillermo/archive/2008/02/24/ajax-how-to-create-a-quot-processing-quot-modal-window-using-updateprogress-and-modalpopup-asp-net-ajax-controls.aspx

Saturday, September 3, 2011

Deletes and inserts when using TransactionScope

he TransactionScope has three modes:

1.Required:If a transaction already exists, then the scope of this transaction will join the existing transaction. Otherwise, it will create its own affairs.

2.RequiresNew:The scope of this transaction will create their own affairs.

3.Suppress:If it is within the scope of the current active transaction, the transaction will neither join the ambient transaction nor create their own affairs. As part of the code need to stay outside in the transaction, you can use this option.



So you can change your code as below 

 
// --------------------------
// Insert Method
// --------------------------
protected void Insert()
{
    using (TransactionScope scope1 = new TransactionScope(TransactionScopeOption.RequiresNew))
    {
        // Code for inserting records.
        scope1.Complete();
    }
}
// --------------------------
// Delete Method
// --------------------------
protected void Delete()
{
using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.RequiresNew))
    {
        // Code for deleting records.
        scope2.Complete();
    }
}
// --------------------------
// Update Method
// --------------------------
protected void Update()
{
using (TransactionScope scope3 = new TransactionScope(TransactionScopeOption.Required))
    {
        Delete();
        Insert();
        scope3.Complete();
    }
}
ref:http://forums.asp.net/p/1590144/4183122.aspx

Cascading DropDownList With Database Example in GridView


Ref 1: With using ajax cascading dropdown list

http://csharpdotnetfreak.blogspot.com/2009/02/ajax-cascading-dropdownlist-database.html

Way 2 :If without using ajax cascading dropdown you can do like this


html code
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="DlBillingDetails_RowDataBound"
                        ShowHeaderWhenEmpty="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
                        GridLines="None" OnRowCommand="dlBillingDetails_RowCommand">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <Columns>
                            <asp:TemplateField HeaderText="Operating Company">
                                <ItemTemplate>
                                    <asp:UpdatePanel ID="updPnlOpComp" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddOperatingCompany" runat="server" AutoPostBack="true" ToolTip='<%#DataBinder.Eval(Container, "DataItemIndex")%>'
                                             OnSelectedIndexChanged="ddOperatingCompany_SelectedIndexChanged">
                                            </asp:DropDownList>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </ItemTemplate>
                            </asp:TemplateField> 
                            <asp:TemplateField HeaderText="Type of Service">
                                <ItemTemplate>
                                    <asp:UpdatePanel ID="updPnlTOS" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddtypeOfService" runat="server">
                                            </asp:DropDownList>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </ItemTemplate>
                            </asp:TemplateField>                          
                        </Columns>
                        <EditRowStyle BackColor="#999999" />
                        <EmptyDataTemplate>
                            No records found!
                        </EmptyDataTemplate>
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>



And the C# code is like below ( only for populating the 2nd dropdown)


 protected void ddOperatingCompany_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            DropDownList ddOperatingCompany = (DropDownList)sender;
            int rowid = Convert.ToInt32(ddOperatingCompany.ToolTip);
            DropDownList ddtypeOfService = (DropDownList)dlBillingDetails.Rows[rowid].FindControl("ddtypeOfService");
            if (ddtypeOfService != null)
            {
                FillCombo.TypeOfServices(ref ddtypeOfService, Convert.ToInt32(ddOperatingCompany.SelectedValue)); // my method to fill dropdowns
            }
            UpdatePanel updPnlTOS = (UpdatePanel)dlBillingDetails.Rows[rowid].FindControl("updPnlTOS");
            if (updPnlTOS != null)
            {
                updPnlTOS.Update(); 
            }
        }
        catch (Exception ex)
        {
            Constants.log.Exception("UserControls_EmpBillingAssignment", "ddOperatingCompany_SelectedIndexChanged", "", ex);
        }
    }

Way 3 : withoud ajax

      just use way 2 but just avoid using the update panel and page would refresh.

Feel free to add your comments \ suggestions \ queries \ better soluions.

Easily Raise Events From ASP.NET ASCX User Controls




ref :
1) http://codebetter.com/brendantompkins/2004/10/06/easily-raise-events-from-asp-net-ascx-user-controls/

Devops links

  Build Versioning in Azure DevOps Pipelines