Click here to Skip to main content
15,903,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I have gridview that contain two columns that is First name and last name .First name taken as a linkbutton and i want when a user click on any cell then it check for its status it the user is active then it show its history otherwise it show an alert 'You are not active.' plz suggest any idea to done it.
<pre lang="c#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Default3 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            //foreach (GridViewRow row in grid1.Rows)
            //    LinkButton lnk = (LinkButton)row.FindControl("lnkbutn");
            //    lnk.Attributes.Add("onclick", "return validate(" + row.RowIndex + ")");
            SqlConnection sql = new SqlConnection("Data Source=.;Initial Catalog=Library_Management;Integrated Security=true");
            SqlCommand cmm = new SqlCommand("Select Firstname,Lastname,Active from Library_management.dbo.User_Master",sql);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmm);
            grid1.DataSource = ds;
    protected void grid1_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
            HiddenField hidn = ((HiddenField)e.Row.FindControl("hdn")) as HiddenField;
            LinkButton lnk = ((LinkButton)e.Row.FindControl("lnkbutn"));

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <script type="text/javascript">
        function validate(dd) {
            if (dd == 'chinkey') {
            else {
    <form id="form1" runat="server">
    <asp:GridView ID="grid1" runat="server" AutoGenerateColumns="false" OnRowDataBound="grid1_RowDataBound">
    <asp:TemplateField HeaderText="First Name">
   <asp:LinkButton ID="lnkbutn" runat="server" CommandArgument='<%#Eval("Firstname") %>'  CommandName="Details" Text='<%#Eval("Firstname") %>'></asp:LinkButton>
   <asp:HiddenField ID="hdn" runat="server" Value='<%#Eval("Active") %>' />
    <asp:BoundField DataField="Lastname" HeaderText="Last NAme" />
Devang Vaja 26-Dec-12 5:36am    
Hi chinkey what is the Problem Here?
is there any error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900