GridView在Edit状态的行是Template中的EditItemtemplat中的控件,
某些时候,需要控制这些行,避免对他们进行操作
情况一:如不加!=EditIndex的控制,则RowDataBound将寻找空间HyperLink,而在Edit状态,控件无效


<asp:TemplateField HeaderText="功能组名称">
<ItemTemplate>
<asp:HyperLink ID="Group_Name_Lab" runat="server"
Text='<%#Eval("Function_GroupName") %>'></asp:HyperLink>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<EditItemTemplate>
<asp:TextBox ID="Group_Name_Box" runat="server"
Text='<%#Eval("Function_GroupName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
处理


1

2

3



4

5

6

7



8

9

10

11

12

13

情况二:如不在EditItemtemplate中写一个相同的HyperLink,则RowDataBound失败,因为无法找到控件


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

处理:


protected void ImgGridView_RowDataBound(
object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1 && e.Row.RowType ==
DataControlRowType.DataRow)
{
string A = ((Label)(e.Row.FindControl("Time_Lab"))).Text;
string B = ((Label)(e.Row.FindControl("Name_Lab"))).Text;
HyperLink HL = (HyperLink)(e.Row.FindControl("Img_Link"));
HL.NavigateUrl =
Config.getOtherPhotoFolder(Convert.ToDateTime(A)) + B;
}
}