开发者

How to Get row by key value or visible index in ASPxGridView then change column value?

Hi

In ASPxGridView, is there a way to get a row by its VisibleIndex or KeyValue so that I can change any column value in it?, I mean something like this:

var row = myGrid.SelectRowByKeyValue(myKeyValue);
OR:
var row = myGrid.SelectRowByVisibleIndex(myKeyValue);  

row["Column1"] = true; 

Edit:

What I'm tring to do 开发者_如何学JAVAis that every time I hit the button I want to check one specific row (I'm using ajax to not reload all the page);

Thanks


This can be done using the ASPxGridView.GetRow() method. NOTE, that changing the value in the DataRow is not enough. If you want these changes to be preserved, save them to the DB.

Since you are using unbound columns, you should handle the CustomUnboundColumnData event and provide modified data for this row within this event handler. The common approach is described in the Providing Data for Unbound Columns topic. If this does not help, please describe in greater details.

UPDATE

Your approach is incorrect. The ASPxGridView does not provide a method to set a text of a certain cell (TD). Instead, you should force the grid to raise the CustomUnboundColumnData event. This can be done using the ASPxGridView's DataBind method. In this event handler, you should determine the KeyField value of the processed row, compare it with the keyField value of the row where the button was clicked and return the required value. This is how I would implement this feature...


I solved it by using this code:

for (int i = 0; i < myGridView.VisibleRowCount; i++)
{
 if ( [My condition] )
   {
     (
       (CheckBox)myGridView
         .FindRowCellTemplateControl(i,
                                     myGridView.Columns["MyColumnName"] as GridViewDataColumn,
                                     "My_Unbound_Control_Name"
                                    )
     ).Checked = true;
   }
}  

I's may not be the right way to do it but I couldn't solve it another way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜