i am working on a web application in asp.net c#. My project is that download mails from g mail and show it in a grid view.i have downloaded mails and displayed in grid view.in my website all the controls are selected only using keyboard keys.i need to select each row from grid view without mouse click by simply enter the row index in a text box then redirect to another page.i tried the code in another grid view and its worked how select grid view row by entering index in a text box but when i applied the same code in my project its not working
Here is my code
inbox.aspx
<asp:Label ID="lblusername" runat="server" Font-Bold="True" Font-Size="X-Large"
ForeColor="#A2979E"></asp:Label>
<br />
<asp:TextBox runat="server" ID="txtindex"></asp:TextBox>
<asp:Button runat="server" Text="Read Mail" ID="btnread"
onclick="btnread_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:GridView ID="gvinbox" runat="server" AutoGenerateColumns="false"
ShowFooter="false" Height="103px" Width="795px" BorderStyle="Solid"
Font-Bold="True" Font-Names="Century Gothic" CellPadding="7"
style="margin-right: 0px">
<Columns>
<asp:BoundField HeaderText="FROM" DataField="From" />
<asp:HyperLinkField HeaderText="SUBJECT" DataNavigateUrlFields="MessageNumber" DataNavigateUrlFormatString="~/Showmessage.aspx?MessageNumber={0}" Target="_blank" DataTextField="Subject" />
<asp:BoundField HeaderText="DATE" DataField="DateSent" />
</Columns>
</asp:GridView>
inbox.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Pop3Client pop3Client;
if (Session["Pop3Client"] == null)
{
pop3Client = new Pop3Client();
pop3Client.Connect("pop.gmail.com", int.Parse("995"), true);
pop3Client.Authenticate("abc@gmail.com", "123456");
Session["Pop3Client"] = pop3Client;
}
else
{
pop3Client = (Pop3Client)Session["Pop3Client"];
}
int count = pop3Client.GetMessageCount();
DataTable dtMessages = new DataTable();
dtMessages.Columns.Add("MessageNumber");
dtMessages.Columns.Add("From");
dtMessages.Columns.Add("Subject");
dtMessages.Columns.Add("DateSent");
dtMessages.Columns.Add("Attachment");
int counter = 0;
for (int i = count; i >= 1; i--)
{
Message message = pop3Client.GetMessage(i);
dtMessages.Rows.Add();
dtMessages.Rows[dtMessages.Rows.Count - 1]["MessageNumber"] = i;
dtMessages.Rows[dtMessages.Rows.Count - 1]["From"] = message.Headers.From.Address;
dtMessages.Rows[dtMessages.Rows.Count - 1]["Subject"] = message.Headers.Subject;
dtMessages.Rows[dtMessages.Rows.Count - 1]["DateSent"] = message.Headers.DateSent.ToLocalTime();
counter++;
if (counter > 10)
{
break;
}
}
gvinbox.DataSource = dtMessages;
gvinbox.DataBind();
}
protected void btnread_Click(object sender, EventArgs e)
{
int index, aid;
if (int.TryParse(txtindex.Text, out index) &&
int.TryParse((gvinbox.DataKeys[index].Value.ToString()), out aid))
{
Response.Redirect(string.Format("Showmessage.aspx?MessageNumber={0}", aid));
}
}