How to Select one Row from Dataset in C# Asp.net

protected void lnkbtnView_Click(object sender, System.EventArgs e)
    {
        DataTable dt = null;
        DataRow[] dr = null;
        LinkButton lnkbtn = (LinkButton)sender as LinkButton;
        //View State having the data
        if (ViewState["GetRecords"] != null)
        {
            dt = (DataTable)ViewState["GetRecords"];


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                // dr = dt.Select("Sno = '" + lnkbtn.CommandArgument + "'");
                if (dt.Rows[i]["Sno"].ToString() == lnkbtn.CommandArgument.ToString())
                {
                }
                else
                {
                    dt.Rows.Remove(dt.Rows[i]);
                    dt.AcceptChanges();
                    i--;
                }
            }
            detailsView.DataSource = dt;
            detailsView.DataBind();
            Bind();
        }


    }

No comments: