c# - How to get value from UserControl of Telerik RadGrid inside DataBound Event and Insert Event -


i'm using telerik grid, here i've placed usercontrol @ radgrid inside gridtemplatecolumn

    <telerik:gridtemplatecolumn uniquename="hardcoded" headertext="hardcoded" allowfiltering="true"                 datafield="accountdesc">                 <itemtemplate>                     <asp:label id="hardcoded" runat="server" text='<%# bind("hardcoded") %>'></asp:label>                 </itemtemplate>                 <edititemtemplate>                     <userctrl:userctrl runat="server" id="lbl" />                 </edititemtemplate>                 <insertitemtemplate>                   <userctrl:userctrl runat="server" id="lbl" />                                         </insertitemtemplate>                 </telerik:gridtemplatecolumn> 

here

here usercontrol combo code

<telerik:radcombobox runat="server" id="hardcoded" >     <items>         <telerik:radcomboboxitem value="1" text="member" selected="true" />         <telerik:radcomboboxitem value="2" text="employee" />         <telerik:radcomboboxitem value="3" text="all" />     </items> </telerik:radcombobox> 

inside databound event want set selected value if press edit button on grid. here code of databound event

  protected void radgrid1_onitemdatabound(object sender, telerik.web.ui.griditemeventargs e)         {             if (e.item.isineditmode)             {                    grideditableitem editableitem = e.item grideditableitem;                     radcombobox hardcoded = editableitem["hardcoded"].controls[0] radcombobox;                   // i've tried   radcombobox hardcoded = (radcombobox)e.item.findcontrol("hardcoded");//it didn't work              }     } 

here error of object reference not set instance of object unable find usercontrol radcombo

similarly if want value inside of insert event i'm unable find combo here code

    protected void radgrid1_insertcommand(object sender, telerik.web.ui.gridcommandeventargs e)     {   string hardcoded = ((radcombobox)ii["hardcoded"].findcontrol("hardcoded")).selectedvalue;    } 

similar exception of object reference not set

instead of using grideditableitem in onitemdatabound event handler, use grideditformitem shown below:

protected void radgrid1_onitemdatabound(object sender, griditemeventargs e) {     if (e.item grideditformitem && e.item.isineditmode)//the grid edit.     {         grideditformitem item = (grideditformitem)e.item;         radcombobox combo = (radcombobox)item.findcontrol("hardcoded");         combo.selectedvalue = "something";     } } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -