asp.net - How can i bind a Database field value to a hidden field inside a gridview -


i use following bind field table hidden field inside gridview getting error system.data.datarowview' not contain property name 'accounttype'.

this how assigned

<asp:templatefield>     <itemtemplate>         <asp:hiddenfield id="hdnaccnttype" runat="server" value='<%#eval("accounttype") %>' />     </itemtemplate> </asp:templatefield> 

is correct or have make corrections?

my stored procedure:

create definer=`root`@`%` procedure `uspgetemployeebankdate`(_empid int(11),  _banktypeid varchar(10),_accounttype varchar(10)) begin select empid,banktypeid,date_format(startdate, '%y-%m-%d')  startdate,date_format(enddate, '%y-%m-%d') enddate  tblemployeebankdata empid=_empid , banktypeid=_banktypeid   , accounttype=_accounttype;  end 

sample code

       if (mlocal_ds.tables[0].rows.count != 0)         {             foreach (datarow drrow in mlocal_ds.tables[0].rows)             {                 if (drrow["banktypeid"].tostring() == "dbalc")                 {                     pnlgrid.visible = false;                     grdbank.visible = true;                     //grddata.visible = false;                      strempid = hiddenfield1.value;                     string accnttype = drrow["accounttype"].tostring();                     string strbanktypeid = drrow["banktypeid"].tostring();                     string mlocal_strstoredprocname = storedprocnames.tblemployeebankdetails_uspemployeebankdetailsdate;                     mlocal_ds = new dataset();                     oemployee.selectid(out mlocal_ds, mlocal_strstoredprocname, strempid, strbanktypeid,accnttype); // here stored procedure executed                     grdbank.datasource = mlocal_ds;                     grdbank.databind();                     pnlchckacc.visible = false;                     pnlprimary.visible = false;                     pnlsecond.visible = false;                     pnlsecondary.visible = false;                     pnlfirst.visible = false;                     pnleditinfo.visible = false;                     break;                 } 

my grid view

     <asp:gridview id="grdbank" runat="server" autogeneratecolumns="false" cellpadding="4"             cssclass="grid" forecolor="#333333" gridlines="none" width="349px" visible="false">             <columns>                 <asp:templatefield>                     <itemtemplate>                         <asp:radiobutton id="rdbtnbank" runat="server" autopostback="true" oncheckedchanged="rdbtnbank_checkedchanged" />                     </itemtemplate>                                         </asp:templatefield>                 <asp:templatefield>                 <itemtemplate>                 <asp:hiddenfield id="hdnaccnttype" runat="server" value='<%# databinder.eval(container.dataitem, "accounttype") %>' />                 </itemtemplate>                 </asp:templatefield>                 <asp:boundfield datafield="empid" headertext="empid">                     <itemstyle cssclass="intitalitefname" />                 </asp:boundfield>                 <asp:boundfield datafield="banktypeid" headertext="banktypeid">                     <itemstyle cssclass="intitalitefname" />                 </asp:boundfield>                 <asp:boundfield datafield="startdate" headertext="start date">                     <itemstyle cssclass="intitalitefname" />                 </asp:boundfield>                 <asp:boundfield datafield="enddate" headertext="end date">                     <itemstyle cssclass="intitalitefname" />                 </asp:boundfield>             </columns>             <rowstyle backcolor="#f7f6f3" forecolor="#333333" />             <footerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" />             <pagerstyle backcolor="#284775" forecolor="white" horizontalalign="center" />             <selectedrowstyle backcolor="#e2ded6" font-bold="true" forecolor="#333333" />             <headerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" />             <editrowstyle backcolor="#999999" />             <alternatingrowstyle backcolor="white" forecolor="#284775" />             <emptydatatemplate>                 nodata display             </emptydatatemplate>         </asp:gridview> 

as muhammed akhtar said original datasource doesn't include accounttype field can't bind anything

you need change stored procedure to:

create definer=`root`@`%` procedure `uspgetemployeebankdate`(_empid int(11),  _banktypeid varchar(10),_accounttype varchar(10)) begin select accounttype, empid,banktypeid,date_format(startdate, '%y-%m-%d')  startdate,date_format(enddate, '%y-%m-%d') enddate  tblemployeebankdata empid=_empid , banktypeid=_banktypeid   , accounttype=_accounttype;  end 

the i've modified right @ beginning of "select" includes accounttype field. if don't include field in original select it's not going included in datasource in turn means can't bind it

hope helps

dave


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -