Click here to Skip to main content
16,016,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai friends,
I am desiging a form with datagridview.
If i click a cell in the datagridview it should display or the 1st cell value of the selected row
Thank you,
regards,
Sissy ram
Posted
Comments
sandeep Nishad 26-Feb-14 1:44am    
where you want to show your grid data value
Sissy Ram 26-Feb-14 1:47am    
As a message box or somewherelse in the sql query

Use DataGridView.SelectionChanged[^] event. Follow the link, use the code there provided and change it depending on your needs.
 
Share this answer
 
You have to use Rowcommand Event

<asp:gridview id="Gemployeemaster" runat="server" backcolor="White" xmlns:asp="#unknown">
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None" onrowcommand="Gemployeemaster_RowCommand"
AllowPaging="True" Width="308px"
onpageindexchanged="Gemployeemaster_PageIndexChanged"
onpageindexchanging="Gemployeemaster_PageIndexChanging">
<footerstyle backcolor="#C6C3C6" forecolor="Black">
<rowstyle backcolor="#DEDFDE" forecolor="Black">
<columns> <asp:buttonfield commandname="Edit" headertext="Edit" text="Edit">
<pagerstyle backcolor="#C6C3C6" forecolor="Black" horizontalalign="Right">
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />


<asp:textbox id="Tempcode" runat="server" xmlns:asp="#unknown">
And code behind


protected void Gemployeemaster_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName =="Edit")
{
Int16 num = Convert.ToInt16(e.CommandArgument);
// which data cell data you want to get in textbox or elsewhere set there position
Tempcode.Text=Gemployeemaster.Rows[num].Cells[1].Text;



}
}
 
Share this answer
 

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