GridView, Repeater 자동 번호 열 증가
15984 단어 GridView
,
, Aspx GridView . .
<Columns>
<asp:TemplateField HeaderText=" " InsertVisible="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Width="5%" />
<ItemTemplate>
<%#Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
, .
<asp:TemplateField HeaderText=" " InsertVisible="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Width="5%" />
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# this.MyListGridView.PageIndex * this.MyListGridView.PageSize + this.MyListGridView.Rows.Count + 1%>'/>
</ItemTemplate>
</asp:TemplateField>
cs , .
<asp:BoundField HeaderText=" " >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Width="5%" />
</asp:BoundField>
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
int indexID = this.myGridView.PageIndex * this.myGridView.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = indexID.ToString();
}
}
GridView OnRowDataBound ;
GridView1_RowDataBound() , :
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// // http://blog.csdn.net/21aspnet
if (e.Row.RowType == DataControlRowType.DataRow)
{
//// ,
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//// ,
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
//// , , RowState
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
//{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm(' :\"" + e.Row.Cells[1].Text + "\" ?')");
//}
}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
“ ”, “ ” 。
<asp:GridView ID="GridView1" runat="server" CellPadding="3" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Font-Size="12px" OnRowDataBound="GridView1_RowDataBound">
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:BoundField DataField=" " HeaderText=" " ReadOnly="True" />
<asp:BoundField DataField=" " HeaderText=" " />
<asp:BoundField DataField=" " HeaderText=" " />
<asp:BoundField DataField=" " HeaderText=" " />
<asp:CommandField HeaderText=" " ShowSelectButton="True" />
<asp:CommandField HeaderText=" " ShowEditButton="True" />
<asp:CommandField HeaderText=" " ShowDeleteButton="True" />
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
, ;
Repeater , ,Container.ItemIndex , :
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
:<%#Container.ItemIndex %>
</ItemTemplate>
</asp:Repeater>
,Repeater , , , , 1 , Container.ItemIndex + 1, :
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
:<%#Container.ItemIndex+ 1 %>
</ItemTemplate>
</asp:Repeater>
。
<asp:RepeaterID="Repeater1"runat="server">
<ItemTemplate>
<%# Container.ItemIndex+1%>
<%# (ContainerasRepeaterItem).ItemIndex+1%>
</ItemTemplate>
</asp:Repeater>
:
Repeater
<FooterTemplate>
<asp:Label ID="lblEmpty" Text=" " runat="server" Visible='<%#bool.Parse((Repeater1.Items.Count==0).ToString())%>'></asp:Label>
</FooterTemplate>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C#의 413은 DataGridView에서 Excel로 데이터 내보내기텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.