Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a Gridview1. In its first column there is employee_id. How can i get that employee id on button click...
Posted
Updated 11-Apr-20 3:20am
Comments
Gopal Rakhal 25-Sep-12 8:28am    
Can u make your question more clear?, do u want to populate gridview with employee_id from database on button click?

Hi

Please add this button colum in your gridview

XML
<Columns>

      <asp:TemplateField HeaderText="CurriculumID" HeaderStyle-ForeColor="White">

         <ItemTemplate>
         <asp:Button ID="lblemployee_id" runat="server" CausesValidation="True"
         PostBackUrl='<%#"WebPageName.aspx?EmployeeID=" + HttpUtility.UrlEncode(Eval("employee_id").ToString())%>' Text="Employee ID></asp:Button>
         </ItemTemplate>
         <ItemStyle HorizontalAlign="Center" />

</Columns>



When you click the button it will get your ID and pass it to your WebPageName.aspx of your choice.

Now Below will be the back code of your WebPageName.aspx

C#
 protected void Page_Load(object sender, EventArgs e)
        {

if (Request.QueryString["EmployeeID"] != null && !string.IsNullOrEmpty(Request.QueryString["EmployeeID"].ToString()))
            {
                Session["EmployeeID"] = Request.QueryString["EmployeeID"].ToString();

                MessageBox.Show(Session["EmployeeID"].String(),"");
            }
        }


Hope it helps...
 
Share this answer
 
call javscript fuction on button click
write following code to your javascript function


C#
var gdv = document.getElementById('Gridview1');

for (var i = 0; i < gdv.rows.length-1; i++) {

    var empId=gdv.rows(i).cells(0).innerHTML;
    alert(empId);
}


i hope it helps you.
 
Share this answer
 
 
Share this answer
 
Comments
bhargavpp 25-Sep-12 6:16am    
protected void Show(object sender, GridViewEditEventArgs e)
{

string RowValue= gv1.Rows[e.NewEditIndex].Cells[0].Text;
// do something with RowValue
}
C#
protected void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
      
       int i = 0;
       try
       {
           int id = int.Parse(grid.DataKeys[e.RowIndex].Values[0].ToString());
           bo.id = id;
           i = bl.DeleteMedicine(bo);
       }
       catch (Exception ex)
       {
           ex.ToString();
       }
      
   }
 
Share this answer
 
v2
GridView1.GetDataRow(I)(J).ToString()
 
Share this answer
 
v2

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