i want to fill one datagrid on click of another datagrid cell values on same page.......plz answer.

i used on datagrid having technology name on click of any technology name i want to fill another datagrid from database on same page.i used viewstate but didn't work......

i want to fill one datagrid on click of another datagrid cell values on same page.......plz answer.

i used on datagrid having technology name on click of any technology name i want to fill another datagrid from database on same page.i used viewstate but didn't work......

can you please put some line of code ? also what are you using in viewstate ? I mean what the values inside viewstate once you click on technology name ?

[using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
datalayer dl = new datalayer();
SqlConnection mycon = new SqlConnection();
SqlCommand mycom = new SqlCommand();
SqlDataAdapter myadapt = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
dl.CheckConnection();
fillgrid();
}


}
public void fillgrid1()
{
if (ViewState["r1"] != null)
{


mycom.CommandText = "select f.faq_title,u.firstname,c.category_name,f.post_date from Question_master f, user_detail u ,category_master c where f.user_id in(select c.category_id from category_master where c.category_id=f.category_id) and c.category_id=" + Request.Params[0].ToString();
mycom.Connection = dl.CheckConnection();
myadapt.SelectCommand = mycom;
myadapt.Fill(ds);
net_dg.DataSource = ds;
net_dg.DataBind();
}
}
public void fillgrid()
{


mycom.CommandText = "select category_id,category_name from Category_master";
mycom.Connection = dl.CheckConnection();
myadapt.SelectCommand = mycom;
myadapt.Fill(dt);
dg.DataSource = dt.DefaultView;
dg.DataBind();


}
public void griditem(object sender, DataGridCommandEventArgs e)
{
string cid = null;
LinkButton lnk = new LinkButton();
if (e.CommandName == "tran")
{
ViewState["r1"] = "0";
lnk = (LinkButton)e.Item.FindControl("lnk1");


cid = dg.DataKeys[e.Item.ItemIndex].ToString();
fillgrid1();
}
}
protected void dg_SelectedIndexChanged(object sender, EventArgs e)
{


}
}

Edited 3 Years Ago by happygeek: fixed formatting

start quote:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    datalayer dl = new datalayer();
    SqlConnection mycon = new SqlConnection();
    SqlCommand mycom = new SqlCommand();
    SqlDataAdapter myadapt = new SqlDataAdapter();
    DataSet ds = new DataSet();
        DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            dl.CheckConnection();
            fillgrid();
        }

    }
    public void fillgrid1()
    {
        if (ViewState["r1"] != null)
        {

            mycom.CommandText = "select f.faq_title,u.firstname,c.category_name,f.post_date from Question_master f, user_detail u ,category_master c where f.user_id in(select c.category_id from category_master where c.category_id=f.category_id) and c.category_id=" + Request.Params[0].ToString();
            mycom.Connection = dl.CheckConnection();
            myadapt.SelectCommand = mycom;
            myadapt.Fill(ds);
            net_dg.DataSource = ds;
            net_dg.DataBind();
        }
    }
    public void fillgrid()
    {

        mycom.CommandText = "select category_id,category_name from Category_master";
        mycom.Connection = dl.CheckConnection();
        myadapt.SelectCommand = mycom;
        myadapt.Fill(dt);
        dg.DataSource = dt.DefaultView;
        dg.DataBind();

    }
    public void griditem(object sender, DataGridCommandEventArgs e)
    {
        string cid = null;
        LinkButton lnk = new LinkButton();
        if (e.CommandName == "tran")
        {
            ViewState["r1"] = "0";
            lnk = (LinkButton)e.Item.FindControl("lnk1");

            cid = dg.DataKeys[e.Item.ItemIndex].ToString();
            fillgrid1();
        }
    }
    protected void dg_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

end quote.

hey thanks for putting the code.

I guess in cid equal category id in your griditem() , you have defined below line of code

cid = dg.DataKeys[e.Item.ItemIndex].ToString();
fillgrid1();

So I suggest pass the cid as string argument in the fillgrid1() method as you have written Select query and binding second grid in this mehtod. In the where clause of Select query you have written code like this Request.Params[0].ToString(); replace code this with the argument you pass in the method "cid".

I hope it will solve your problem !

Please mark the thread as solved if your problem get solved.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.