Get cell value on click of link button


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Get cell value on click of link button

  1. #1
    Join Date
    May 2006
    Posts
    29

    Get cell value on click of link button

    int count1;

    protected void Page_Load(object sender, EventArgs e)
    {
    SqlConnection Conn;
    Conn = new SqlConnection("Data Source=AB2\\SQLEXPRESS;Initial Catalog=Tiger;Integrated Security=True");

    Conn.Open();

    SqlCommand salCmd = new SqlCommand("select count(V.Vendor_name),V.Vendor_code,V.vendor_name,V.contact_name1,V.contact_mobile1 from vendor V INNER join stock S on S.vendor_code = V.Vendor_code group by V.vendor_name,V.Vendor_code,V.contact_name1,V.contact_mobile1", Conn);
    SqlDataReader dr = salCmd.ExecuteReader();

    while (dr.Read())
    {
    count1 = (int)dr[0];

    string code = dr[1].ToString();
    string name = dr[2].ToString();
    string name1 = dr[3].ToString();
    string mobile1 = dr[4].ToString();


    SqlConnection conDataGrid = new SqlConnection("Data Source=AB2\\SQLEXPRESS;Initial Catalog=Tiger;Integrated Security=True");
    SqlDataAdapter adapterDataGrid = new SqlDataAdapter("select prod_id,prod_name,quantity,inprice from stock where vendor_code ='" + code + "'", conDataGrid);
    DataSet ds = new DataSet();
    adapterDataGrid.Fill(ds);



    DataGrid dg = new DataGrid();
    dg.Width = 600;
    dg.GridLines = GridLines.Both;
    dg.CellPadding = 1;
    dg.ForeColor = System.Drawing.Color.Black;
    dg.BackColor = System.Drawing.Color.Beige;
    dg.AlternatingItemStyle.BackColor = System.Drawing.Color.Gainsboro;
    dg.HeaderStyle.BackColor = System.Drawing.Color.Brown;
    dg.DataSource = ds;
    dg.AutoGenerateColumns = true;


    BoundColumn datagridcol = new BoundColumn();
    datagridcol.HeaderText = "ID";
    datagridcol.Visible = true ;
    datagridcol.DataField = "prod_id";
    dg.Columns.Add(datagridcol);

    ButtonColumn selectcol = new ButtonColumn();
    selectcol.ButtonType = ButtonColumnType.LinkButton;
    selectcol.Text = "ChangeVendor";
    selectcol.CommandName = "Select";
    dg.Columns.Add(selectcol);

    dg.DataBind();

    Label lb = new Label();
    lb.Visible = true;
    lb.Font.Bold = true;
    string valls = name + " " + " " + name1 + " " + " " + mobile1;

    PlaceHolder1.Controls.Add (dg);







    }
    Conn.Close();

    }
    protected void dg_ItemCommand(object source, DataGridCommandEventArgs e)
    {

    string productid;
    TableCell pid = e.Item.Cells[0];
    productid = pid.Text;
    Response.Write(productid);

    }

    Above is the code I have used for the dynamic bound column. Now I have created Bound columns for the Link button and prodid.
    But when I click the ChangeVendor (Link Button) I have to get the prodid of that cell .
    I tried with the Item command but I not able to fetch any value.
    Please tell me how I have to fetch the value.
    The same way I use to do for the control Datagrid , it worked fine .
    Tell me immediately please

  2. #2
    Join Date
    Jun 2006
    Posts
    5
    ItemCommand event will be raised when there is any Button in the Datagrid is clicked. So, Make it as an HyperLink Column and Pass ur value in the queyString to the target page.

    Clear?

Similar Threads

  1. Linking a button click to a mouse event?
    By fulcanelli in forum Java
    Replies: 10
    Last Post: 11-06-2005, 03:29 PM
  2. Replies: 2
    Last Post: 05-16-2005, 11:22 AM
  3. Connecting to DB2 using VB 6.0
    By Randy in forum VB Classic
    Replies: 5
    Last Post: 03-30-2001, 10:13 PM
  4. How to simulate button click?
    By Serge in forum VB Classic
    Replies: 6
    Last Post: 06-14-2000, 07:07 AM
  5. How to simulate button click?
    By Serge in forum VB Classic
    Replies: 0
    Last Post: 06-10-2000, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center