2

I wanto check the state of checkbox which is inside the data item template in devexpress grid view when the user click the ok button here is my aspx code for gridviewColumn

<Columns>
                                    <dx:GridViewDataColumn Caption="Data Source" FieldName="dataSrc" VisibleIndex="1"></dx:GridViewDataColumn>
                                    <dx:GridViewDataColumn Caption="Download" FieldName="dwnloadConfig" VisibleIndex="2" Width="70px" >
                                        <DataItemTemplate>
                                            <dx:ASPxCheckBox ID="cbDwnloadConfig" ClientInstanceName="cbDwnloadConfig
                                                " runat="server" >

                                            </dx:ASPxCheckBox>
                                        </DataItemTemplate>                                        
                                </Columns>

Now when ok button is clicked i want to check the state of cbDwnloadConfig on server side

I used following code on cs file to access the dataitem template control but the checked state is always false.

ASPxCheckBox cbDwnload = gvDataSrc.FindRowCellTemplateControl(rwIndex[i], gvDataSrc.Columns["dwnloadConfig"] as GridViewDataColumn, "cbDwnloadConfig") as ASPxCheckBox;

So what is the proper way to check the state of checkbox which is inside the dataitemtemplate?

Sangit Gurung
  • 111
  • 1
  • 11

2 Answers2

0

It may be that you are binding your grid view in PageLoad method and that may cause this behaviour.

You should bind your grid view in following way

if(!page.IsPostBack)
{
 //BIND YOUR GRID
}

Above will prevent rebinding of gridview when button is clicked.

Ronak Patel
  • 2,570
  • 17
  • 20
  • Thanks @Patel for your response but m not binding grid view on page_Load But some research on devexpress griview and dataitem template i came to know that the dataitemtemplate is not bind with Gridview Datasource. – Sangit Gurung Aug 11 '14 at 04:02
0

Well for those of you having the same issue i have found solution to the problem, I had to use callback for this issue.

<Columns>
                <dx:GridViewDataColumn Caption="Data Source" FieldName="dataSrc" VisibleIndex="1"></dx:GridViewDataColumn>
              <dx:GridViewDataColumn Caption="Download" FieldName="dwnloadConfig" VisibleIndex="2" Width="70px" >
                <DataItemTemplate>
                   <dx:ASPxCheckBox ID="cbDwnloadConfig" ClientInstanceName="cbDwnloadConfig" runat="server" >
             <ClientSideEvents CheckedChanged="function(s,e)
                                                    {dwnloadSrc.PerformCallback(s.GetChecked());
                                                    }"></ClientSideEvents>
                 </dx:ASPxCheckBox>
               </DataItemTemplate>                                        
</Columns>

C#

 protected void dwnloadSrc_OnCallback(object source, CallbackEventArgs e)
{
    var param = e.Parameter;
    //now check the paramater
    //and do your magic 
}

you also can pass two or multiple parameter at once from the front end/aspx for that just do this:

dwnloadSrc.PerformCallback(s.GetChecked()+'_'+ gv.FocusedRowsIndex())

and at the Code behind you can check the parameter :

    var param = e.Parameter;
    var newParam = param.Split('_');
    bool state = Convert.ToBoolean(newParam[0]);
    int rwIndex = Convert.ToInt32(newParam[1]);

Thanks!

Sangit Gurung
  • 111
  • 1
  • 11