以下代码未显示任何错误,仍未提供输出。
Asp.code
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" onclick="CheckAll(this)"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<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:ImageField>
<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" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:LinkButton ID="link" runat="server" Text="Choose" CssClass="linkbutton"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Report">
<ItemTemplate>
<asp:Button ID="Button5" runat="server" Text="Get details" BackColor="#33CCFF" CssClass="getdetails"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<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" />
</asp:GridView>
C#代码
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;
}
}
答案 0 :(得分:1)
尝试此代码。问题在CommandName
,因为您没有在LinkButton中提供CommandName
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:LinkButton ID="link" runat="server" Text="Choose" CssClass="linkbutton" CommandName="Choose"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>