2015-02-04 9 views
1

이전 주문을 gridview에 표시합니다. 그들은 마지막 열의 재전송 버튼을 눌러 주문이 지불되거나 그 상태를 지나친 상태에서 주문을 다시 보낼 수 있습니다.gridview에서 데이터를 가져 오는 방법

먼저있는 gridview : 고객이 주문을 지불 할 때

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" pagesize="10" 
    BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1" EmptyDataText="You have no orders yet" 
    GridLines="Vertical" OnRowCommand="GridView1_RowCommand"> 
    <AlternatingRowStyle BackColor="#DCDCDC"/> 
    <Columns> 
     <asp:BoundField DataField="TD_OrdID" HeaderText="Ord" InsertVisible="False" ReadOnly="True" SortExpression="TD_OrdID" /> 
     <asp:BoundField DataField="TD_OrdDate" DataFormatString="{0:d}" ItemStyle-HorizontalAlign="Right" HeaderText="Date" SortExpression="TD_OrdDate" ><ItemStyle HorizontalAlign="Right"></ItemStyle></asp:BoundField> 
     <asp:BoundField DataField="TD_PD_PackageName" HeaderText="Package Name" ItemStyle-HorizontalAlign="Left" SortExpression="TD_PD_PackageName" > </asp:BoundField> 
     <asp:BoundField DataField="TD_OSName" ItemStyle-HorizontalAlign="Right" HeaderText="Status" SortExpression="TD_OSName" > <ItemStyle HorizontalAlign="Right"></ItemStyle></asp:BoundField> 
     <asp:BoundField DataField="TD_InvID" HeaderText="Inv" InsertVisible="False" ReadOnly="True" SortExpression="TD_InvID" /> 
     <asp:BoundField DataField="TD_InvPaid" HeaderText="Paid" ItemStyle-HorizontalAlign="Right" SortExpression="TD_InvPaid" ><ItemStyle HorizontalAlign="Right"></ItemStyle></asp:BoundField> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <asp:Button runat="server" ID="btnResend" CommandName="Resend" Text="Resend" CommandArgument="<% ((GridViewRow) Container).RowIndex 
         %>" OnDataBinding="btnResend_DataBinding" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> 
    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> 
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> 
    <RowStyle BackColor="#EEEEEE" ForeColor="Black" Font-Size="Small" HorizontalAlign="Center"/> 
    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> 
    <SortedAscendingCellStyle BackColor="#F1F1F1" /> 
    <SortedAscendingHeaderStyle BackColor="#0000A9" /> 
    <SortedDescendingCellStyle BackColor="#CAC9C9" /> 
    <SortedDescendingHeaderStyle BackColor="#000065" /> 
    </asp:GridView> 

이제 데이터 바인딩이 재전송 버튼을 선택합니다 : 잘 작동

protected void btnResend_DataBinding(object sender, EventArgs e) 
{ 
    // only set button to enable when customer can resend document! 

    Button btn = (Button)(sender); 
    // enable button for status                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         emailed, paid and closed 
    btn.Enabled = ((Eval("TD_OSName").ToString().Equals("closed")) || 
        (Eval("TD_OSName").ToString().Equals("paid")) || 
        (Eval("TD_OSName").ToString().Equals("emailed"))); 

} 

. 버튼을 비활성화합니다. 어쩌면 더 좋은 해결책은 대신 그것을 숨기는 것입니다. 그러나 이것은 내 관심사가 아닙니다. 나를 위해 도전

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Resend") 
    { 
     // Retrieve the row index stored in the 
     // CommandArgument Property 
     int index = Convert.ToInt32(e.CommandArgument); 

     // Retrieve the row that contains the button 
     // from Rows collection. 
     GridViewRow row = GridView1.Rows[index]; 

     // add code 
     int ordId = Convert.ToInt32(row.Cells[0].Text); 

     lblMessage.ForeColor = System.Drawing.Color.Green; 
     //lblMessage.Text = displayMessages.YourDocumentResent() + "OrdID:" + ordId; 
     //lblMessage.Text = displayMessages.YourDocumentResent(); 
     lblMessage.Text = Convert.ToString(e.CommandArgument); 
    } 
} 

그러나 선택한 행을 얻고 행의 순서 식별을 읽기 위해 :

이제 행 명령은 버튼을 누를 때 행에서 "ordId"값을 얻을 수 . 나는 이것을 계속해서 고글 거리고 내가 실수를 한 곳을 볼 수 없다.

라인 : 심지어 마이크로 소프트의 MSDN 페이지에이를 발견하는 경우

int index = Convert.ToInt32(e.CommandArgument) 

입력 문자열 실패는 올바른 형식

아니었다?! 나는 e.commandArgument을 표시하는 경우

나는 참조 : <% ((GridViewRow) Container).RowIndex %>

사람은 그래서 고객이 다시 보내기 버튼을 누르면 한 행에서 TD_OrdID의 값 OrdId를 얻을 수 있습니다 도와 드릴까요?

미리 감사드립니다.

답변

1
<% ((GridViewRow) Container).RowIndex %> 

#이 누락되었습니다.

시도 :

<%# ((GridViewRow) Container).RowIndex %> 
+1

오류를 수정하는 달콤한는하지만 지금은 값이 0으로 얻을? – Rene

+0

index = 0? 또는 ordId = 0입니까? – Mate

+1

죄송합니다. 모든 것이 잘 못되었습니다. 오타를 보았습니다. 정말 고마워요. :) 지금 작동합니다. – Rene

관련 문제