Get row data in repeater on LinkButton click event asp.net c#

get value from epeater control For example, repater was populate with datatable and binddata to repeater. Repeater can be binded from any database MYSQL ,MSSQL or Oracle but procedure are same.
In LinkButton by eval bind all necessary data in CommandArgument with some unique special char , later we are using split with the same char at server side.

Download

Example Source Snippets - RepeaterMultiButton.zip

How to get row data in LinkButton click event in repeater ?


               linkButton click event in repeater
                 

namespace : using System.Data

LinkButton by eval bind all necessary data in CommandArgument


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindData();
    }

    protected void BindData()
    {
        DataTable dt = new DataTable();

        dt.Columns.Add("ItemID", typeof(string));
        dt.Columns.Add("ItemName", typeof(string));
        dt.Columns.Add("ItemDescription", typeof(string));
        dt.Columns.Add("ItemQty", typeof(string));

        DataRow dr = null;
        for (int i = 1; i <4; i++)//populate datatable
        {
            dr = dt.NewRow();
            dr["ItemID"] = i.ToString();
            dr["ItemName"] = "Item Name - " + i.ToString();
            dr["ItemDescription"] = "Description - " + i.ToString();
            dr["ItemQty"] = "10";

            dt.Rows.Add(dr);
        }

        //bind  repeater
        Repeater1.DataSource = dt;
        Repeater1.DataBind();
    }

    protected void Edit_Click(Object sender, EventArgs e)
    {  
        LinkButton lbtn = (LinkButton)(sender);
        string commArgument = lbtn.CommandArgument;

        //split commmad Argument
        string[] spltTxt = commArgument.Split('<');        
        string ItemID = spltTxt[0];
        string ItemName = spltTxt[1];
        string ItemDescription = spltTxt[2];
        string ItemQty = spltTxt[3];

        //loop repeater
        foreach (RepeaterItem item in Repeater1.Items)
        {
              Label lblRow = (Label)item.FindControl("rowID");
              if (lblRow.Text == ItemID)
              {
                  //do you work here


                  lblResult.Text = lblRow.Text +  "- Row ID Got Click";
                  lblData.Text = "Name :" + ItemName + " Description :" + ItemDescription + " Qty :"+ ItemQty;
                  break;
              }
        }
    }
}
                 

smartsnipps.ecomparefiles.com © 2019, All Rights Reserved | Disclaimer: smartsnipps.eCompareFiles.com is free to use any code snippets without guarantee