2014-11-14 2 views
0

У меня есть страница с 3 GridViews.Получить текущий GridView

<div id="Export" runat="server" class="headeropt noprint"> 

      <asp:LinkButton runat="server" ID="buttonexport" OnClick="buttonexport_Click" OnClientClick="Javascript:Noshow();" CssClass="btn btn-default"> 
       <asp:Image runat="server" ImageUrl="/images/Excel-16.gif" /> 
       <asp:Label runat="server" Text="Export" /> 
      </asp:LinkButton> 
     </div> 
<div class="col-md-12"> 
     <asp:GridView ID="grid1" runat="server" CellPadding="0" CssClass="table" CellSpacing="0" OnRowDataBound="grid1_RowDataBound" AutoGenerateColumns="false" GridLines="Vertical" BorderStyle="Solid" ShowFooter="true" OnRowEditing="grid1_RowEditing" datakeynames="grid1"> 
      <Columns> 
       <asp:TemplateField HeaderText="Name"> 
        <ItemTemplate> 
         <asp:LinkButton ID="lnkname" runat="server" CausesValidation="false" CommandName="Edit" CommandArgument='<%# Eval("name") %>' Text='<%# Eval("name") %>'></asp:LinkButton> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:TemplateField HeaderText="Company"> 
        <ItemTemplate> 
         <asp:Label ID="Label2" runat="server" Text='<%# Eval("company") %>'></asp:Label> 
        </ItemTemplate> 
        <ItemStyle CssClass="alinha-direita" /> 
        <FooterStyle CssClass="alinha-direita" /> 
       </asp:TemplateField> 
      </Columns> 
     </asp:GridView> 

     <asp:GridView ID="grid2" runat="server" CellPadding="0" CssClass="table" CellSpacing="0" OnRowDataBound="grid2_RowDataBound" AutoGenerateColumns="false" GridLines="Vertical" BorderStyle="Solid" ShowFooter="true" OnRowEditing="grid2_RowEditing" datakeynames="grid2"> 
      <Columns> 
       <asp:TemplateField HeaderText="Product Family"> 
        <ItemTemplate> 
         <asp:LinkButton ID="lnkprdfamily" runat="server" CausesValidation="false" CommandName="Edit" CommandArgument='<%# Eval("prdfamily") %>' Text='<%# Eval("prdfamily") %>'></asp:LinkButton> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:TemplateField HeaderText=""> 
        <ItemTemplate> 
         <asp:Label ID="Label2" runat="server" Text='<%# Eval("quantity") %>'></asp:Label> 
        </ItemTemplate> 
        <ItemStyle CssClass="alinha-direita" /> 
        <FooterStyle CssClass="alinha-direita" /> 
       </asp:TemplateField> 
      </Columns> 
     </asp:GridView> 
     <asp:GridView ID="grid3" runat="server" CellPadding="0" CssClass="table" CellSpacing="0" OnRowDataBound="grid3_RowDataBound" AutoGenerateColumns="false" GridLines="Vertical" BorderStyle="Solid" ShowFooter="true" datakeynames="grid3"> 
      <Columns > 
       <asp:TemplateField HeaderText="Product"> 
        <ItemTemplate> 
         <asp:Label ID="Label2" runat="server" Text='<%# Eval("product") %>'></asp:Label> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:TemplateField HeaderText="Price"> 
        <ItemTemplate> 
         <asp:Label ID="Label3" runat="server" Text='<%# Eval("price") %>'></asp:Label> 
        </ItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
     </asp:GridView> 
    </div> 

как вы можете видеть, первая сетка соединяется со второй, а вторая с третьей. То, что я хочу знать, в любой момент, чтобы получить сетку, которую я просматриваю в данный момент.

Только что отредактировал добавление linkButton, который экспортирует сетку в excel. Вот почему мне нужен gridview, в котором я сейчас работаю, так что команда экспорта работает в любое время.

Вот код экспорта:

protected void buttonexport_Click(object sender, EventArgs c) 
{ 
    Master.Page.Form.Attributes.Remove("onsubmit"); 
    CB.ChangeControlsToValue(grid1); 
    string attachment = "attachment; filename=File.xls"; 
    //Response.ClearContent(); 
    Response.AddHeader("content-disposition", attachment); 
    Response.ContentType = "application/ms-excel"; 
    StringWriter sw = new StringWriter(); 
    HtmlTextWriter htw = new HtmlTextWriter(sw); 
    grid1.RenderControl(htw); 
    Response.Write(sw.ToString()); 
    Response.End(); 
} 

Спасибо.

+0

вопрос = 0 смысл – Rich

+0

Просто отредактировали запрос. – Xixo

ответ

0

Nevemind, получил решение.

Я только что проверил тот, который виден в данный момент и работает с ним.

bool list = grid1.Visible; 
    if (list) 
    { CB.ChangeControlsToValue(grid1); } 

и так далее ....

Смежные вопросы