Important Points


  1. To wrap the Text in source Code of Visual Studio
        Ctrl  E + Ctrl  W

    2.  To Format Ctrl A + Ctrl K + Ctrl D


   3. To hide Tree View in Crystal Report :

        CrystalReportViewer.DisplayGroupTree = false;

  4. How to remove    from Gridview

        Include the line ConvertEmptyStringToNull="true" HtmlEncode="false"  HtmlEncodeFormatString="false"  in theBound field

        eg.  <asp:BoundField DataField="Serial No" HeaderText="Serial No" ConvertEmptyStringToNull="true" HtmlEncode="false" HtmlEncodeFormatString="false" />

5. To remove rows of the datatable while loading to the Combobox

If the datatable contains 4 rows and u want only first two rows
eg .

Machine
Accesories
Spare
oil


Required only

Machine
Accesories

then,

 dsAssetType.Tables[0].Rows.RemoveAt(3);
  dsAssetType.Tables[0].Rows.RemoveAt(2);


Coding eg.

  //--------Asset Type ComboBox----
            MasAssetTypeBLL masAssetTypeBLL = new MasAssetTypeBLL();
            DataSet dsAsset = new DataSet();
            dsAsset = masAssetTypeBLL.SelectAssetTyp(0);// load the data to dataset
            dsAsset.Tables[0].Rows.RemoveAt(3);// first remove row 3
            dsAsset.Tables[0].Rows.RemoveAt(2); // remove row 2
            ddlAssetType.DataSource = dsAsset.Tables[0];//load it to ddl
            ddlAssetType.DataTextField = "AssetTypeName";
            ddlAssetType.DataValueField = "ID";
            ddlAssetType.DataBind();


5a.  How to Delete a row from Grid

  1.  Create function Datagridtodatatable() [Refer Ponit No. 8]
  2.  Create Datatable globally (before pageload)
  3.  Remove the  e.RowIndex form the datatable
  4.  Bind it to grid.



eg.            Datagridtodatatable();
                dttable.Rows.RemoveAt(e.RowIndex);
                dtgGrid.DataSource =  dttable;
                 dtgGrid .DataBind();


6.To bind the field in the Template of Datagrid(Grid View).


In aspx source add the following line
Text='<%# Bind("field")%>'

In text change event

 TextBox txt = (TextBox)sender;

                GridViewRow row = (GridViewRow)txt.NamingContainer;

                int i = row.RowIndex;

                TextBox month = ((TextBox)dtgMachineDetails.Rows[i].FindControl("txtMachineMonthly"));


eg.

  <asp:TextBox ID="txtMachineMonthly" runat="server" ontextchanged="txtMachineMonthly_TextChanged" AutoPostBack="True" Text='<%# Bind("MonthlyCost")%>'   Height="22px" Width="100px" CssClass="style5"></asp:TextBox>


protected void txtMachineMonthly_TextChanged(object sender, EventArgs e)
        {


         TextBox txt = (TextBox)sender;

                GridViewRow row = (GridViewRow)txt.NamingContainer;

                int i = row.RowIndex;

                TextBox month = ((TextBox)dtgMachineDetails.Rows[i].FindControl("txtMachineMonthly"));

}





7. To make text field readonly

 if (!IsPostBack)
            {
            textname.Attributes.Add("readonly", "readonly");
}

8. How to transfer multiplerec from grid to datatable...Datagridtodatatable

  1. . Create Datatable 
  2.  Declare Datatable globally (before pageload)
  3.   In for loop count no. of rows in grid
  4.  Add it to Datatable

     



eg.

 private void CreateDataTableACC()
        {
            dttable.Columns.Add("Accessories ID");
             dttable .Columns.Add("Asset Code");
             dttable .Columns.Add("Asset Name");
             dttable .Columns.Add("Remarks");
        }


        private void DatagridTodatatable
        {
            CreateDataTableACC();
            for (int i = 0; i < dtgAccessoriesDetails.Rows.Count; i++)
            {
                 dttable .Rows.Add(
                    dtgAccessoriesDetails.DataKeys[i]["Accessories ID"],
                    dtgAccessoriesDetails.Rows[i].Cells[1].Text,
                    dtgAccessoriesDetails.Rows[i].Cells[2].Text,
                    dtgAccessoriesDetails.Rows[i].Cells[3].Text);
               
            }

        }


9. Button to Add record to Gridview using Datatable

  1.  Create  Datagridtodatatable [refer pointNo. 8]
  2.   Create New Row
  3.  Add row to table
  4. Bind it to grid
eg.

 private void CreateDataTable()
        {
            dttable.Columns.Add("Accessories ID");
             dttable .Columns.Add("Asset Code");
             dttable .Columns.Add("Asset Name");
             dttable .Columns.Add("Remarks");
        }


        private void DatagridTodatatable
        {
            CreateDataTable();
            for (int i = 0; i < dtgAccessoriesDetails.Rows.Count; i++)
            {
                 dttable .Rows.Add(
                    dtgAccessoriesDetails.DataKeys[i]["Accessories ID"],
                    dtgAccessoriesDetails.Rows[i].Cells[1].Text,
                    dtgAccessoriesDetails.Rows[i].Cells[2].Text,
                    dtgAccessoriesDetails.Rows[i].Cells[3].Text);
               
            }

        }


protected void btnAdd_Click(object sender, EventArgs e)
        {


                DatagridTodatatable ();// old records are transfered to datatable
                DataRow dr =  dttable .NewRow(); // new row created
                dr["Accessories ID"] = lblAccessoryID.Text.Trim();
                dr["Asset Code"] = txtAccessoryName.Text.Trim();
                dr["Asset Name"] = txtAccessoryName1.Text.Trim();
                dr["Remarks"] = txtAttachmentAccessoryRemarks.Text.Trim();
                dtAssetAccessories.Rows.Add(dr); // add new row to datatable
                dtAssetAccessories.AcceptChanges();
                dtgAccessoriesDetails.DataSource = dtAssetAccessories; //bind to grid
                dtgAccessoriesDetails.DataBind();


}

10. How to reset Autogenerated no to 0 in tables of SQL server

DBCC CHECKIDENT(M_Type, RESEED, 0)


Comments