Translate

C# Winform Create Dynamic TabPage and add User Control

Tuesday, November 22, 2016 Category : 0

  List<string> openTabs = new List<string>();
  List<TabPage> openTabPages = new List<TabPage>();

  private void OpenPage(Control control, string OperationName)
        {

            if (!openTabs.Exists(m => m.ToString() == OperationName))
            {
                TabPage tb = new TabPage();
                tb.Text = OperationName;
                tb.Controls.Add(control);
                tabControl1.TabPages.Add(tb);

                // set align position
                int main_width = tabControl1.Width;
                int control_width = control.Width;
                int posX = (main_width - control_width) / 2;
                control.Location = new Point(posX, 0);

                tabControl1.SelectedTab = tb;

                openTabs.Add(OperationName);
                openTabPages.Add(tb);
            }
            else
            {
                foreach (TabPage tb in tabControl1.TabPages)
                {
                    Control ctl = tb.Controls[0];
                    if (ctl != null)
                    {
                        if (ctl.GetType() == control.GetType())
                        {
                            tabControl1.SelectedTab = tb;
                        }
                    }
                }
            }


        }

C# Winform Add Border to UserControl

Category : 0

protected override void OnPaint(PaintEventArgs e)
{

base.OnPaint(e);
int borderWidth = 3;
Color borderColor = SystemColors.AppWorkspace;
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor,
borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth,
ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid);
}


Source : https://social.msdn.microsoft.com/Forums/windows/en-US/ca9a9df3-c37e-455b-8fae-58d88ed77d90/change-border-around-usercontrol?forum=winformsdesigner
 

Fixed header and scrollable body

Tuesday, July 12, 2016 Category : 0



<div class="Top1 base">
    <table>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
          ....
        </tr>
    </table>
</div>
<div class="Top2 base">
    <table>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
            </td>
            <td>5
            </td>
            <td>6
            </td>
            <td>7
          .....
        </tr>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
            </td>
          .....
        </tr>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
            </td>
          ...
        </tr>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
           ....
        </tr>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
            ........
        </tr>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
            </td>
            <td>5
           ...........
        </tr>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
            </td>
            .....
        </tr>
        <tr>
            <td>1
            </td>
            <td>2
            </td>
            <td>3
            </td>
            <td>4
            </td>
            <td>5
            </td>
            ......
        </tr>
    </table>
</div>




.base{
    width:250px;
    overflow:scroll;
    max-height:100px;
}

.Top1
{
    overflow:hidden;
    width: 230px;
 }


$('.Top2').bind('scroll', function(){
  $(".Top1").scrollLeft($(this).scrollLeft());
});




Source : http://jsfiddle.net/A79e2/10/

ASP.NET Expand grid view

Wednesday, May 4, 2016 Category : 0

Source :  http://www.aspsnippets.com/Articles/ASPNet-Nested-GridViews-GridView-inside-GridView-with-Expand-and-Collapse-feature.aspx


<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
    DataKeyNames="CustomerID" OnRowDataBound="OnRowDataBound">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <img alt = "" style="cursor: pointer" src="images/plus.png" />
                <asp:Panel ID="pnlOrders" runat="server" Style="display: none">
                    <asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid">
                        <Columns>
                            <asp:BoundField ItemStyle-Width="150px" DataField="OrderId" HeaderText="Order Id" />
                            <asp:BoundField ItemStyle-Width="150px" DataField="OrderDate" HeaderText="Date" />
                        </Columns>
                    </asp:GridView>
                </asp:Panel>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField ItemStyle-Width="150px" DataField="ContactName" HeaderText="Contact Name" />
        <asp:BoundField ItemStyle-Width="150px" DataField="City" HeaderText="City" />
    </Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        gvCustomers.DataSource = GetData("select top 10 * from Customers");
        gvCustomers.DataBind();
    }
}


protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string customerId = gvCustomers.DataKeys[e.Row.RowIndex].Value.ToString();
        GridView gvOrders = e.Row.FindControl("gvOrders") as GridView;
        gvOrders.DataSource = GetData(string.Format("select top 3 * from Orders where CustomerId='{0}'", customerId));
        gvOrders.DataBind();
    }
}
 
 
 
 
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $("[src*=plus]").live("click", function () {
        $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
        $(this).attr("src", "images/minus.png");
    });
    $("[src*=minus]").live("click", function () {
        $(this).attr("src", "images/plus.png");
        $(this).closest("tr").next().remove();
    });
</script>
 
 
 
 

ASP.NET C# Document Download from Database

Sunday, April 24, 2016 Category : , , 0


Load document byte from sql server database. save it to temporary storeage , and view in browser.

public void Download() {

string fileName = "abc.doc";
string _path = Request.PhysicalApplicationPath + "Temp/" + fileName;

byte[] filebyte = new byte[0]; // load from database

File.WriteAllBytes(_path, filebyte );

oR.showReportAjax(ResolveUrl("~/Temp/" + fileName), this.GetType(), this, UpdatePanel1);

}

public void showReportAjax(string pageUrl, Type cType, Page oPage, Control ctrl)
{
string url = ResolveClientUrl(pageUrl) ;

ScriptManager.RegisterStartupScript(ctrl, typeof(string), "redirect", "window.open('" + url + "');", true);

} 
 

Method 2


System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
        response.ClearContent();
        response.Clear();
        response.ContentType = "text/plain";
        response.AddHeader("Content-Disposition", 
                           "attachment; filename=" + fileName + ";");
        response.TransmitFile(Server.MapPath("FileDownload.csv"));
        response.Flush();    
        response.End();

 

ASP.NET Jquery Auto complete with selected value

Friday, March 25, 2016 Category : 0


 function InitAutoCompl3() {

                                         
                                             $("#<%=txtAccountName.ClientID %>").autocomplete({
                                                 source: function (request, response) {
                                                     $.ajax({
                                                         url: '<%=ResolveUrl("~/DataWebService.asmx/GetAccounts2") %>',
                                                         data: "{ 'prefixText': '" + request.term + "'}",
                                                         dataType: "json",
                                                         type: "POST",
                                                         contentType: "application/json; charset=utf-8",
                                                         success: function (data) {

                                                             response($.map(data.d, function (item) {
                                                                 return {
                                                                     label: item.split('~')[1],
                                                                     val: item.split('~')[0]
                                                                 }
                                                             }))
                                                         },
                                                         error: function (response) {
                                                             alert(response.responseText);
                                                         },
                                                         failure: function (response) {
                                                             alert(response.responseText);
                                                         }
                                                     });
                                                 },
                                                 select: function (e, i) {
                                                     $("#<%=HFAcId2.ClientID %>").val(i.item.val);
                                                 },
                                                 minLength: 1
                                             });
                                     };


ASP.NET call Java function in every async postback

Category : , 0

 $(document).ready(function () {
                                         var prm = Sys.WebForms.PageRequestManager.getInstance();
                                         prm.add_initializeRequest(InitializeRequest);
                                         prm.add_endRequest(EndRequest);

                                         // Place here the first init of the autocomplete
                                         InitAutoCompl3();  // in web user control
                                     });

                                     function InitializeRequest(sender, args) {
                                     }

                                     function EndRequest(sender, args) {
                                         // after update occur on UpdatePanel re-init the Autocomplete
                                         InitAutoCompl3();
                                     }

Powered by Blogger.