This is a migrated thread and some comments may be shown as answers.

formview with radgrid

5 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
feras
Top achievements
Rank 1
feras asked on 19 Sep 2008, 12:19 AM
hi, i just downloaded your controls and they look wonderful, so i will make tests to finalize my decision to purchase.

i am trying to do the following,i dont want to use radgrid edit functions,  i want to add a rad grid with records and i want to click edit button then it will show form view with the records data so i can update or insert a new record, my questions are

-what is the best approach to make edit button?

-best way to pass the record id to the form view without page refresh?

-i want when i click edit to hide the grid and show the form view and vise versa when i update the record to hide form view and show grid view so should i add to the button click even a command to make grid.visible = false and form view.visible = true and vise versa ? or should i do that through java script to change the css class for each ?

-when i finish the edit and go back to hte grid i want the edited row grid to be highlighted ?

- best approch to ajexefy the whole process?

thx in advanced

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Sep 2008, 10:32 AM
Hello Feras,

1.You can create an EditButton by setting the CommandName property of the button as shown below.
 <asp:ImageButton ID="ImageButton1" ImageUrl="~/images (2)/Edit Image (2).bmp" CommandName="Edit" runat="server" /> 

2. You can get the DataKeyValue(recordID) of the row and store it in a global variable and pass it in the FormView.

3.You can try the following code to hide the grid  and show the Form view on clicking Edit and hide form view and show grid view on clicking Update.
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "Edit") 
        { 
            RadGrid1.Visible = false
            FormView1.Visible = true;            
        } 
    } 
 // on the click event of the UpdateButton
protected void UpdateButton_Click(object sender, EventArgs e) 
    { 
        RadGrid1.Visible = true
        FormView1.Visible = false
    } 
 

5.To Ajaxify the whole process you can use RadAjaxManager or RadAjaxPanel and place the controls in it.


Thanks
Princy.
0
feras
Top achievements
Rank 1
answered on 19 Sep 2008, 10:37 AM
hi,
thx alot for the fast reply, but can you kindly please give me the code for
2. You can get the  DataKeyValue(recordID) and store it in a global variable and pass it in the FormView.
and what about regarding

-when i finish the edit and go back to hte grid i want the edited row grid to be highlighted ?

thx alot again
0
Princy
Top achievements
Rank 2
answered on 19 Sep 2008, 10:49 AM
Hello feras,
  2.You can get the  DataKeyValue as shown below.
cs:
 string ID; 
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    {          
 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem data = (GridDataItem)e.Item; 
           ID = data.GetDataKeyValue("RecordID").ToString();           
        } 
   } 

4.You can try the following code to set the edited row selected.
cs:
  bool isSelected; 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
          if (e.Item is GridEditableItem &&  e.Item.IsInEditMode) 
            { 
                  if (!e.Item.OwnerTableView.IsItemInserted) 
                    { 
                        Session["selIndex"] = e.Item.ItemIndex; 
                    } 
                    e.Item.Selected = true
                   isSelected = true;    
             } 
     } 
 
     protected void RadGrid1_PreRender(object sender, EventArgs e) 
     { 
 
        if (!isSelected && Session["selIndex"] != null) 
        { 
            RadGrid1.MasterTableView.Items[(int)Session["selIndex"]].Selected = true
            Session["selIndex"] = null; 
        } 
    } 

Thanks
Princy.
0
feras
Top achievements
Rank 1
answered on 19 Sep 2008, 11:01 AM
just lovely :)
thx a lot   i will carry on testing it
0
Monish
Top achievements
Rank 1
answered on 16 Nov 2009, 12:54 PM
Hello Feras,

    I am also working on similar kind of scenario... My issue is, I am not able to bind the form view with the row that is selected on the gridview... the formview is always poping up with the (values of) first record of the gridview... I won't be able to share my code as I reverted my code back...
   Did you got your test working? Could your share (markup and / or code behind if required) what you did ?

Thanks...
Monish.
Tags
Grid
Asked by
feras
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
feras
Top achievements
Rank 1
Monish
Top achievements
Rank 1
Share this question
or