c# - how to fill the dropdownlist in grip grouping control using syncfusion in asp.net -


i having grid grouping control in syncfusion asp.net first column cell type combobox.here need fill dropdownlist in pageload.i wrote below code:

sqlcommand cmd = new sqlcommand("select item_id, item_name productsnrwmtrls item_ctgry in('r','b')", con);          sqldataadapter   da = new sqldataadapter(cmd);            datatable dtlocl = new datatable();             da.fill(dtlocl);          dropdownlist ddlrwmtrl1 = (dropdownlist)gridgroupingcontrol1.findcontrol("ddlrwmtrl");          ddlrwmtrl1.datatextfield = "item_name";         ddlrwmtrl1.datavaluefield = "item_id";         ddlrwmtrl1.datasource = dtlocl;         ddlrwmtrl1.databind(); 

but @ line ddlrwmtrl1.datatextfield = "item_name"; showing error : object reference not set instance of object.

you can fill dropdownlist in syncfusion gridgroupingcontrol using rowdatabound. add dropdown item template in aspx file:

[**aspx**]      <syncfusion:gridcolumndescriptor mappingname="city" headertext="city">           <itemtemplate>                <asp:dropdownlist id="ddlcity" runat="server"></asp:dropdownlist>           </itemtemplate>     </syncfusion:gridcolumndescriptor> 

rowdatabound event

**[cs]**     protected void page_load(object sender, eventargs e)     {         if (!ispostback)             getdata();         this.gridgroupingcontrol1.rowdatabound += gridgroupingcontrol1_rowdatabound;     }      protected void gridgroupingcontrol1_rowdatabound(object sender,rowdataboundeventargs e)     {         if (e.element.kind == displayelementkind.record)         {             (int = 0; < e.row.cells.count; i++)             {                 if (((gridcell)e.row.cells[i]).columndescriptor.name == "city")                 {                     myconnection = new sqlconnection(connectionstring);                     myconnection.open();                     dropdownlist ddl = (dropdownlist)e.row.cells[i].findcontrol("ddlcity");                     sqlcommand cmd = new sqlcommand("select distinct city employees",                                               myconnection);                     sqldataadapter da = new sqldataadapter(cmd);                     dataset ds = new dataset();                     da.fill(ds);                     myconnection.close();                     ddl.datasource = ds;                     ddl.datatextfield = "city";                     ddl.datavaluefield = "city";                     ddl.databind();                     ddl.items.insert(0, new listitem("--select--", "0"));                 }             }         }     } 

you grid dropdown below

enter image description here


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -