<asp:GridView ID="grdDocumento" runat="server" Width="940px" PageSize="3" BackColor="White" BorderColor="#EEEEEE" BorderStyle="Solid" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="Horizontal" AllowPaging="True" AutoGenerateColumns="False" onpageindexchanging="grdDocumento_PageIndexChanging" onselectedindexchanged="grdDocumento_SelectedIndexChanged" onrowcreated="grdDocumento_RowCreated"> <PagerSettings Mode="NumericFirstLast" FirstPageText="Primeira" LastPageText="Última" PageButtonCount="5" /> <FooterStyle BackColor="White" ForeColor="#000066" BorderStyle="Solid" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" BorderStyle="Solid" /> <SelectedRowStyle BackColor="#A0A4AC" Font-Bold="True" ForeColor="White" BorderStyle="Solid" /> <HeaderStyle BackColor="#D84040" Font-Bold="True" ForeColor="White" BorderStyle="Solid" /> <AlternatingRowStyle BackColor="#EEEEEE" BorderStyle="Solid" /> <Columns> <asp:CommandField SelectText="»»" ShowCancelButton="False" ShowSelectButton="True"> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:CommandField> <asp:BoundField DataField="Campo1" HeaderText="Campo1" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo2" HeaderText="Campo2" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo3" HeaderText="Campo3" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo4" HeaderText="Campo4" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" /> </asp:BoundField> <asp:BoundField DataField="Campo5" HeaderText="Campo5" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo6" HeaderText="Campo6" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo7" HeaderText="Campo7" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo8" HeaderText="Campo8" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo9" HeaderText="Campo9" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo10" HeaderText="Campo10" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> <asp:BoundField DataField="Campo11" HeaderText="Campo11" HtmlEncode="False" FooterText=""> <ItemStyle BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" /> </asp:BoundField> </Columns> </asp:GridView> |
onpageindexchanging="grdDocumento_PageIndexChanging" onselectedindexchanged="grdDocumento_SelectedIndexChanged" onrowcreated="grdDocumento_RowCreated" |
Para criar o método OnRowCreated, basta selecionar o GridView, clicar em propriedades mais especificamente em Events, escolher o RowCreated clicando duas vezes em cima. (Image 1)

protected void grdDocumento_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.Cells.Count == 12) { e.Row.Cells[6].Visible = false; e.Row.Cells[7].Visible = false; e.Row.Cells[8].Visible = false; e.Row.Cells[9].Visible = false; e.Row.Cells[10].Visible = false; e.Row.Cells[11].Visible = false; } } |
Com a tela preenchida, o usuário pode clicar e selecionar uma linha específica. Todos os valores pegos podem preencher outros campos, inclusive os escondidos do usuário. Neste método, além de ter que criar no gridview clicando duas vezes em Events, vou mostrar como pegar os dados escondidos. (Code 4)
protected void grdDocumento_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow _linha = grdDocumento.SelectedRow; String _caminho = _linha.Cells[8].Text + @"\" + _linha.Cells[9].Text; _caminho = _caminho.Replace(@"\", "|"); ChamaMeuMetodo(_caminho); } |