2013-12-18 56 views
1

我有一個ASPXGridView,我想知道如何從網格中獲取值,我想要獲得每行的「供應商名稱」和「樂隊名稱」值。我只想要這些列的值。如何獲取ASPXGridView某一列的行值

我是否需要查看DataSource還是?

我附上了一張照片,我正在研究的網格是最底層的。對此客戶的所有限制。

enter image description here

下面是底部格柵的標記。

<dxwgv:ASPxGridView ID="GVFullResults" 
     runat="server" Width="100%" 
     AutoGenerateColumns="False" DataSourceID="ODSFullResultsGrid" 
     KeyFieldName="Id"> 
     <SettingsBehavior ConfirmDelete="True" /> 
     <Styles> 
      <Header BackColor="#CCCCFF" Font-Bold="True" Font-Names="Arial" 
       Font-Size="10px"> 
      </Header> 
     </Styles> 
     <Columns> 
      <dxwgv:GridViewCommandColumn Caption="Edit" VisibleIndex="0" Width="55px"> 
       <EditButton Visible="True"> 
       </EditButton> 
       <DeleteButton Visible="True"> 
       </DeleteButton> 
      </dxwgv:GridViewCommandColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="CarrierId" VisibleIndex="1" 
       Caption="Vendor" Width="35px"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="CarrierName" VisibleIndex="2" 
       Width="140px" Caption="Vendor Name"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="CustomerId" VisibleIndex="3" 
       Caption="Customer" Width="45px"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="CustomerName" VisibleIndex="4" 
       Width="140px"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="BandId" VisibleIndex="5" 
       Caption="Band" Width="45px"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="BandName" VisibleIndex="6" 
       Width="140px"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="Restriction" VisibleIndex="7" 
       Width="50px"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="DateCreated" VisibleIndex="8"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="CreatedBy" VisibleIndex="9" 
       Width="55px"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn FieldName="Comments" VisibleIndex="10"> 
       <EditFormSettings CaptionLocation="None" /> 
       <EditItemTemplate> 
        <div style="float:right"> 
        Comments: 
        <dxe:ASPxMemo ID="CommentsMemo" runat="server" Height="71px" Width="170px"> 
        </dxe:ASPxMemo> 
        </div> 
       </EditItemTemplate> 
       <CellStyle> 
        <Border BorderColor="Silver" BorderStyle="Solid" /> 
       </CellStyle> 
      </dxwgv:GridViewDataTextColumn> 
      <dxwgv:GridViewDataTextColumn Caption="Id" FieldName="Id" Visible="False" 
       VisibleIndex="11"> 
       <EditFormSettings Visible="False" /> 
      </dxwgv:GridViewDataTextColumn> 
     </Columns> 
     <SettingsPager PageSize="75"> 
     </SettingsPager> 
     <Settings ShowVerticalScrollBar="True" VerticalScrollableHeight="300" /> 
    </dxwgv:ASPxGridView> 
+0

您是否已經填充gridview的?如果是這樣,你用什麼來填充它? – Humpy

+0

請發佈您的代碼,顯示如何獲取GridView的數據以及GridView標記。 – mason

+0

@Humpy我已經添加了標記代碼,所有網格都使用存儲過程填充 – jeffry

回答

2

試試這個。

int indexOfColumnToGet = some number; 
gridview.Rows[rowIndex].Cells[indexOfColumnToGet].Text 
1

如果我理解正確的話,你這個應該工作..

foreach(GridViewRow gvr in gvGridView1.Rows) 
{ 
    ((Label)gvr.FindControl("lblVendorName")).Text; 
    ((Label)gvr.FindControl("lblBandName")).Text; 
} 
+2

感謝您的幫助,但.Rows不是一種方法,可以在ASPXGridView上使用... – jeffry

相關問題