我有网格,它是 selectIndexchange 事件。
我的 aspx 代码:
<asp:GridView ID="gvClients" runat="server" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None"
OnRowEditing="gvClients_RowEditing" Font-Size="Medium"
onrowcancelingedit="gvClients_RowCancelingEdit"
onrowdeleting="gvClients_RowDeleting" onrowupdating="gvClients_RowUpdating"
onselectedindexchanging="gvClients_SelectedIndexChanging">
<FooterStyle BackColor="Tan" />
<Columns>
<asp:CommandField ShowEditButton="True" ButtonType="Image" CancelImageUrl="~/Images/Cancel.png"
UpdateImageUrl="~/Images/save.png" EditImageUrl="~/images/Edit.png" ItemStyle-Width="25px"
UpdateText="Update" CancelText="Cancel" />
<asp:CommandField ShowDeleteButton="true" DeleteImageUrl="~/Images/delete.png" ButtonType="Image"
ItemStyle-Width="25px" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat="server" ID="imgSelect" CommandName="Select" AlternateText="Select"
ImageUrl="~/Images/allowed.png" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ClientId" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("ClientId")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtClientClientId" Text='<%#Eval("ClientId") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ClientName" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("ClientName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtClientClientName" Text='<%#Eval("ClientName") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("Active")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtClientActive" Text='<%#Eval("Active") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="Tan" Font-Bold="True" HorizontalAlign="Left" Font-Size="Smaller" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
现在,我的SelectedIndexChanging
代码:
protected void gvClients_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridViewRow row = gvClients.Rows[e.NewSelectedIndex];
txtClientNumber.Text = row.Cells[3].Text;
}
问题是,文本来了 null 。有数据,但不是值,而是空值....同样的代码也在另一个页面上工作。所以,请告诉我。我做错了什么?
谢谢