Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Not working ? No error showing web page


Asp.code


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="624px" CssClass="grid"
AllowPaging="True" AllowSorting="True" BackColor="White" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" PageSize = "5"
OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" DataKeyNames="id" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">

<columns> <asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" onclick="CheckAll(this)"/>
</HeaderTemplate>
<itemtemplate>
<asp:CheckBox ID="chkchild" runat="server" />


<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="updatedby" HeaderText="updatedby" SortExpression="updatedby" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
<asp:BoundField DataField="mail" HeaderText="mail" SortExpression="mail" />

<asp:BoundField DataField="imagename" HeaderText="imagename" SortExpression="imagename" />
<%--<asp:CommandField ShowEditButton="true" ButtonType="image" EditImageUrl="~/images/delete.jpg" HeaderText="Delete" />--%>

<asp:ImageField DataImageUrlField="uploadimage" HeaderText="uploadimage" ControlStyle-Width = "60" ControlStyle-Height = "100">



<asp:CommandField ShowEditButton="True" />

<asp:TemplateField HeaderText="Delete" >
<itemtemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/delete.jpg"
OnClientClick="return confirm('Are you sure you want to delete?')" Text="Delete" CommandName="Delete" />


<asp:TemplateField HeaderText="Update">
<itemtemplate>
<asp:LinkButton ID="link" runat="server" Text="Choose" CssClass="linkbutton">



<asp:TemplateField HeaderText="Report">
<itemtemplate>
<asp:Button ID="Button5" runat="server" Text="Get details" BackColor="#33CCFF" CssClass="getdetails"/>




<footerstyle backcolor="White" forecolor="#000066">
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="White" forecolor="#000066" horizontalalign="Left">
<rowstyle forecolor="#000066">
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F1F1F1">
<sortedascendingheaderstyle backcolor="#007DBB">
<sorteddescendingcellstyle backcolor="#CAC9C9">
<sorteddescendingheaderstyle backcolor="#00547E">




C# code

protected void OnRowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName=="Choose")
{
GridViewRow row = ((e.CommandSource as LinkButton).NamingContainer as GridViewRow);
TextBox2.Text = row.Cells[2].Text;
TextBox3.Text = row.Cells[3].Text;
TextBox4.Text = row.Cells[4].Text;
}
}
Posted
Updated 6-Dec-17 19:39pm

1 solution

you need to add onrowcommand event to GridView like below
<asp:gridview id="GridView1" onrowcommand="OnRowCommand" 
 
Share this answer
 
v2
Comments
Member 10918596 8-Nov-14 2:47am    
thank you..
DamithSL 8-Nov-14 2:57am    
you are welcome!

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