c# - Bind/Display the two different columns data together inside a Dropdown for a particluar Id in "Edit" mode of RadGrid -


i have 4 columns in telerik radgrid
1) account code (only column shown in "edit" , "add" mode - dropdown)
2) account description
3) amount
4) remark

below "add" mode code using:

html code:

    <mastertableview showheaderswhennorecords="true" autogeneratecolumns="false" datakeynames="accountcodeid" insertitemdisplay="top"                         insertitempageindexaction="showitemoncurrentpage" showfooter="true" commanditemdisplay="top">                                                                 <columns>                                   <telerik:grideditcommandcolumn></telerik:grideditcommandcolumn>                                    <telerik:gridtemplatecolumn uniquename="accountcode" headertext="account code">                                     <itemtemplate>                                       <asp:label id="lblaccode" text='<%# eval("accountcode") %>' runat="server"></asp:label>                                     </itemtemplate>                                     <edititemtemplate>                                       <asp:dropdownlist id="ddlaccode" datatextfield="accountdescription" datavaluefield="accountcodeid" runat="server"/>                                      </edititemtemplate>                                  </telerik:gridtemplatecolumn>                                   <telerik:gridboundcolumn datafield="accountdescription" headertext="description" uniquename="accountdescription" sortexpression="accountdescription" insertvisiblitymode="alwayshidden" readonly="true" ></telerik:gridboundcolumn>                                  <telerik:gridboundcolumn aggregate="sum" datafield="amount" headertext="amount" footertext="total : " uniquename="amount" sortexpression="amount"></telerik:gridboundcolumn>                                  <telerik:gridboundcolumn datafield="remark" headertext="ifca remark" uniquename="remark" sortexpression="remark">                                   </telerik:gridboundcolumn>                                       <telerik:gridbuttoncolumn commandname="delete" text="delete" uniquename="deletecolumn"></telerik:gridbuttoncolumn>                                                                                                       </columns>                           <editformsettings>                            <editcolumn buttontype="imagebutton" />                           </editformsettings>                           <commanditemsettings addnewrecordtext="add new record" refreshtext="refresh"></commanditemsettings> </mastertableview> 

c# code:

protected void rggstaccode_itemdatabound(object sender, griditemeventargs e)     {         if (e.item grideditableitem && e.item.isineditmode)         {             grideditableitem item = e.item grideditableitem;              string companycode = ddlcompany.selectedvalue.tostring();             dropdownlist list = item.findcontrol("ddlaccode") dropdownlist;             list.datatextfield = "accountdescription";             list.datavaluefield = "accountcodeid";             list.datasource = getacccode(companycode);             list.databind();             list.items.insert(0, "- select -");         }            }  protected void rggstaccode_insertcommand(object sender, gridcommandeventargs e)     {         grideditableitem item = e.item grideditableitem;          dropdownlist accountcode = item.findcontrol("ddlaccode") dropdownlist;         string selectedacccode = accountcode.selecteditem.text;          //split dropdown 2 vales         string acccode = selectedacccode.substring(0, selectedacccode.indexof('-')).trim(); //getting a/c code         string accdesc = selectedacccode.substring(selectedacccode.indexof('-') + 1).trim(); //getting a/c descr          insertaccountcode(new guid(tempguid.text), acccode, accdesc);         bindgrid();         rggstaccode.rebind();     } 

"account code" column shown in "add" , "edit" mode of radgrid. dropdown in have bind 2 values i.e., account code + account description, , have show , save in separate columns of database. (i.e, account code value in account code column , account description value in description column)

now requirement that: while doing "edit", want bind/display "account code" column data , "account description" column data inside dropdown, saved in database particular id. bind dropdown while edit.

and later after editing dropdown item, data saved 2 different columns of db doing while adding records.

only not getting how display/bind 2 different columns data inside dropdown when doing "edit". please suggest solution.

i hope able make requirement clear. in advance.

hmm.. clear thoughts issue.

what type of databind using ? whether advanced databind / sqldatasource databind?

anyway have 4 columns in grid right! change select query below one.

select accountcode, accountdesc, amount, remark, convert(varchar(20),accountcode)+' '+accountdesc accdetail yourtablename <-- note down accdetails.

i'm concatanating fields accountcode , accountdesc accdetail (with empty space ). grid has 5 rows. hide fifth row in gridview using visible="false" in accdetail column. don't modify accountcode column.
change in dropdownlist.

 <asp:dropdownlist id="ddlaccdetail" datatextfield="accdetail" datavaluefield="accdetail" runat="server"/> 

now dropdown show content accountcode accountdesc in editmode.

on insert, following code change

protected void rggstaccode_insertcommand(object sender, gridcommandeventargs e)  {    grideditableitem item = e.item grideditableitem;    dropdownlist ddlaccdetail = item.findcontrol("ddlaccdetail") dropdownlist;        string accdetail = ddlaccdetail.selecteditem.text;    string acccode=accdetail.split(' ')[0];   //splitting string     string accdesc=accdetail.split(' ')[1];   //with added empty space      insertaccountcode(new guid(tempguid.text), acccode, accdesc);    bindgrid();    rggstaccode.rebind();  }
thats it, hope work. keep in mind if have empty space in accountcode or accountdesc field default, need change empty space special character ( - , * , / ,)


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -