Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have set property of paging in gridview. But when i click on next button , i get error, i.e.

There is no row at position 0.

That error occurs in event of row command. I didn't get why this error has occurred. Can u plz help me to solve the problem?
Posted

Try this
C#
<asp:gridview id="myGridView" runat="server" >
 AllowPaging="True" 
 OnPageIndexChanging="myGridView_PageIndexChanging"
 PageSize="5" ></asp:gridview>

C#
protected void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {     

        myGridView.PageIndex = e.NewPageIndex;
        myGridView.DataBind();
    }
 
Share this answer
 
v2
Comments
mona_12 3-Dec-12 1:53am    
I have tried wat u said...
but stil error is coming...
pradiprenushe 3-Dec-12 2:07am    
Can you give flow of what are you doing? means paging click select click like that in sequence & give the line where you are getting this exception. I think this is not paging issue.
My code is

XML
<asp:GridView ID="GridView_Inbox" runat="server" AutoGenerateColumns="False"
                         onrowcommand="GridView_Inbox_RowCommand" AllowPaging="true" PageSize="1" OnPageIndexChanging="GridView_Inbox_PageIndexChanging">
                         <PagerSettings Mode="NumericFirstLast" PageButtonCount="2"  FirstPageText="First" LastPageText="Last"/>
                    <Columns>
                        <asp:BoundField DataField="MESSAGE_ID" HeaderText="Message ID" Visible="false"  />
                        <asp:BoundField DataField="FIRST_NAME" HeaderText="First Name"  />
                        <asp:BoundField DataField="LAST_NAME" HeaderText="Last Name" />
                        <asp:BoundField DataField="MESSAGE_SUBJECT" HeaderText="Subject" />
                        <asp:BoundField DataField="MESSAGE_CONTENT" HeaderText="Message" >
                            <HeaderStyle HorizontalAlign="Center" Width="400px" />
                        </asp:BoundField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton_Inbox_Read" runat="server" CommandArgument='<%# Eval("MESSAGE_ID") %>'>Read</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                   </asp:GridView>



My .cs code is
C#
protected void GridView_Inbox_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       int MSG_ID = Convert.ToInt32(e.CommandArgument);
       SysATGlobal.DB.ExecuteDMLCommand("UPDATE DSMailBox.HDR_MESSAGES SET READ_STATUS=1 WHERE MESSAGE_ID= " + MSG_ID + " ");
       dt = SysATGlobal.DB.ExecuteSelectQuery("SELECT [INBOX].MESSAGE_CONTENT  from DSMailBox.HDR_MESSAGES [INBOX] INNER JOIN DSProfile.HDR_PROFILE [SENDER] ON [SENDER].[PROFILE_ID] = [INBOX].[SENDER_ID] WHERE [INBOX].[RECEIVER_ID] = " + SysATGlobal.DB.MyProfile.ProfileID + "  AND [INBOX].[MESSAGE_ID]=" + MSG_ID + "", false);
       msg = dt.Rows[0].ItemArray.GetValue(0).ToString();  //Here i get that exception
       TextBox_Inbox.Text = msg;


   }
 
Share this answer
 
Comments
pradiprenushe 3-Dec-12 3:43am    
your datatable is not having data. Check query returns data or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900