Example #1
0
 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     try
     {
         Label           lb  = (Label)GridView1.Rows[e.RowIndex].FindControl("Label6");
         DropDownList    ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1");
         RadioButtonList rbl = (RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("RadioButtonList1");
         CheckBoxList    chb = (CheckBoxList)GridView1.Rows[e.RowIndex].FindControl("CheckBoxList1");
         TextBox         txb = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");
         string          T1  = GridView1.Rows[e.RowIndex].Cells[0].Text;
         string          T2  = txb.Text;
         string          T3  = chb.SelectedValue;
         string          T4  = ddl.SelectedValue;
         string          T5  = rbl.SelectedValue;
         ClassLibraryProject.EFDF.GRIDSIMPLEEDIT GE = new ClassLibraryProject.EFDF.GRIDSIMPLEEDIT {
             ID = Convert.ToInt16(GridView1.Rows[e.RowIndex].Cells[0].Text), TBOX = txb.Text, CB = chb.SelectedValue, RB = rbl.SelectedValue, DD = ddl.SelectedValue
         };
         ClassLibraryProject.EFDF.DAL dl = new ClassLibraryProject.EFDF.DAL();
         dl.GetEDITUpdateLessItemsProp(GE);
         GridView1.EditIndex = -1;
         ShowGrid();
     }
     catch (Exception exc)
     {
         //For any exception in data handling
         //Can register a script block to give popup for error and ask to cancel and report the web administrator
     }
 }
Example #2
0
        //Bind() is used to two-way databinding.So when used with the proper type of datasource, it will pull the altered values out of the GridView or other control and save them back to the database.
        //Eval() is a one - way, "read only" way to bind the values.

        //For Editing the data, we can use Hidden field control for passing ID field value To and Fro

        protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // Retrieve the underlying data item. In this example
            // the underlying data item is a DataRowView object.
            //DataRowView rowView = (DataRowView)e.Row.DataItem;// Error - Unable to cast object of type 'ClassLibraryProject.EFDF.LessPropItemData' to type 'System.Data.DataRowView'. As this is a object datasource and  not Datatable datasource .
            ClassLibraryProject.EFDF.GRIDSIMPLEEDIT rowViewObject = (ClassLibraryProject.EFDF.GRIDSIMPLEEDIT)e.Row.DataItem;// Error - Unable to cast object of type 'ClassLibraryProject.EFDF.LessPropItemData' to type 'System.Data.DataRowView'. As this is a object datasource and  not Datatable datasource .

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                    DropDownList    dd = (DropDownList)e.Row.FindControl("DropDownList1");
                    RadioButtonList rb = (RadioButtonList)e.Row.FindControl("RadioButtonList1");
                    CheckBoxList    cb = (CheckBoxList)e.Row.FindControl("CheckBoxList1");
                    dd.SelectedValue = rowViewObject.DD;            // rowView[1].ToString();
                    rb.SelectedValue = rowViewObject.RB;            // rowView[2].ToString();
                    string[] CBArray = rowViewObject.CB.Split(','); // rowView[3].ToString().Split(',');

                    foreach (ListItem li in cb.Items)
                    {
                        li.Selected = CBArray.Contains(li.Value);
                    }
                }
            }
        }