c# - Row count of nested GridView is always zero -


parent grid-view gvagreement.

child grid-view gvproducts.

code used :

protected void gvagreement_onrowdatabound(object sender, gridviewroweventargs e)     {             if (e.row.rowtype == datacontrolrowtype.datarow)             {                 string agreementid = gvagreement.datakeys[e.row.rowindex].value.tostring();                 gridview gvproducts = e.row.findcontrol("gvproducts") gridview;                 gvproducts.datasource = getdata(string.format("select dbo.agreement.*, dbo.agreementlist.*, dbo.store.*, dbo.agreementlist.agreement_id agreid dbo.agreement inner join dbo.agreementlist on dbo.agreement.agreement_id = dbo.agreementlist.agreement_id inner join dbo.store on dbo.agreementlist.proid = dbo.store.pro_id (dbo.agreementlist.agreement_id = '{0}')", agreementid));                 gvproducts.databind();                 int count = gvproducts.rows.count;                session["countgrid"] = count;              }      }  protected void gvproducts_rowcommand(object sender, gridviewcommandeventargs e)     {       if (convert.toint32(session["countgrid"].tostring()) == 1)                     {                         string message = "alert('agreement @ least must have 1 product');";                         scriptmanager.registerclientscriptblock(sender control, this.gettype(), "alert", message, true);                     }     } 

i tried define count global value gives zero.

when / how databind child grid? should inside onrowdatabound event of master grid as, presumably, contents rely on row of master grid in located.

protected void gvagreement_onrowdatabound(object sender, gridviewroweventargs e) {         if (e.row.rowtype == datacontrolrowtype.datarow)         {             string agreementid = gvagreement.datakeys[e.row.rowindex].value.tostring();             gridview gvproducts = e.row.findcontrol("gvproducts") gridview;             if(gvproducts != null)             {                   gvproducts.datasource = [some query or data source here]                   gvproducts.databind();             }             int count = gvproducts.rows.count;             session["countgrid"] = count;         }  } 

edited after comments

you shouldn't store row count in session variable. don't need to, because place want make use of (in rowcommand event), can find out is.

something like:

protected void gvproducts_rowcommand(object sender, gridviewcommandeventargs e) {   var gvproducts = e.row.findcontrol("gvproducts") gridview;   if (gvproducts != null && gvproducts.rows.count < 1)   {       string message = "alert('agreement must have @ least 1 product');";       scriptmanager.registerclientscriptblock(sender control, this.gettype(), "alert", message, true);   } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -