Hello everyone,
I need to find the gridview row number on click of a row on Page_load not on any other event..!! How do i do that?Please help me..!!
regards,
Francis P.
Ferns
![]() |
0 |
![]() |
Sorry Francis, but I believe you're out of luck as the Page.Load event is way too early in the Page lifecyle to pick this up. This would most likely be done in the SelectedIndexChanged, RowCommand, or Click event of a Button.
Thanks, Ed
Microsoft MVP - ASP/ASP.NET
![]() |
0 |
![]() |
Hi,
Ya i understand that. Is there any other way i can find out the Row number.I ll tell you my actual requirement.Im implementing the ICallbackEventHandler and implement the RaiseCallbackEvent event tht is where i need the row number of the gridview so that i can retrieve certain details based on the row number.I tried the other way round that is on rowboundData event of the gridview i add onclick attributes and store that in a hidden field but somehow i m not able to figure out y the hidden field value does not show up in the RaiseCallbackEvent..!!! Is there any other way i can do this..??Thanks n regards,
Francis P.
Ferns
![]() |
0 |
![]() |
Hi:
Please try this:
protected string temp;
public void RaiseCallbackEvent(string eventArgument)
{
temp = "At:" + DateTime.Now.ToString() + " you selected row " + eventArgument + ".";
}public string GetCallbackResult()
{
return temp;
}
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.GetCallbackEventReference(this, "param", "handleResultFromServer", "context");}
<script type="text/javascript">
function callToServer(index)
{
var param = index;
var context = "";
WebForm_DoCallback('__Page',param,handleResultFromServer,context,null,false)}
function handleResultFromServer(result, context)
{ alert(result);
}
</script><asp:GridView DataSourceID="SqlDataSource1" ID="GridView2" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input onclick='<%# "callToServer(" +((GridViewRow)Container).RowIndex + ")"%>' type="button" value="Call to Server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>Regards
Sincerely,
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hello Allen,
Well thts exactly wat i was looking for !.Thank you. I have another question.I have this requirement of develpoing a website like say for example www.franferns.com and on navigation to a different page the URL in the address bar should not change it should always be www.franferns.com
I tried the URL Rewriting article but was not able to figure out anything.. Anything you can suggest me .Your any help would be appreciated.Thanks n Regards
Francis P.
Ferns
![]() |
0 |
![]() |
Hi:
I think url rewriting should work. You can refer to:
http://msdn2.microsoft.com/en-us/library/ms972974.aspx
Regards
Sincerely,
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hi Allen this is regarding the gridview once i click on the cells in the gridview i get an popup with details of the clicked row..!!At times on click nothing happens. Its like it never calls any of the function it ll just be's blank..!!! And then after i refresh starts working..!!!Any clue of wat is it that im goin wrong?
Regards,
Francis P.
Ferns
![]() |
0 |
![]() |
Hi:
My suggestion is to use AJAX control to do so:
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<cc2:PopupControlExtender ID="PopupControlExtender1" runat="server" PopupControlID="DetailsView1" TargetControlID="GridView4">
</cc2:PopupControlExtender>
<asp:GridView DataKeyNames="theID" AutoGenerateSelectButton="true" ID="GridView4" DataSourceID="SqlDataSource1" runat="server">
</asp:GridView>
<asp:DetailsView BackColor="AliceBlue" DataSourceID="SqlDataSource2" ID="DetailsView1" runat="server" Height="50px" Width="125px">
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AConnectionString %>"
SelectCommand="SELECT * FROM Table_1"
onselecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:AConnectionString %>"
SelectCommand="SELECT * FROM Table_1 where theID=@theID"
onselecting="SqlDataSource1_Selecting">
<SelectParameters><asp:ControlParameter Name="theID" ControlID="GridView4" />
</SelectParameters>
</asp:SqlDataSource>Learn and download ASP.NET AJAX:
Regards
Sincerely,
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hi,
I cannot use that because the site im hosting does not support AJAX.!! Any idea as to y the previous solution tht implements ICallBack interface acts in tht way?
Regards,
Francis P.
Ferns
![]() |
0 |
![]() |
Hi:
OK please try this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication5.WebForm3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function callToServer(index)
{
var param = index;
var context = "";
WebForm_DoCallback('__Page',param,handleResultFromServer,context,null,false)}
function handleResultFromServer(result, context)
{
document.getElementById("detailsview").innerHTML=result;
}
</script></head>
<body>
<form id="form1" runat="server">
<div id="detailsview">
</div>
<div>
<asp:GridView DataKeyNames="theID" DataSourceID="SqlDataSource1" ID="GridView2" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input onclick='<%# "callToServer(" +((GridViewRow)Container).RowIndex + ")"%>' type="button" value="Call to Server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:DetailsView DataSourceID="SqlDataSource2" ID="DetailsView1" runat="server" Height="50px" Width="125px">
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AConnectionString %>"
SelectCommand="SELECT * FROM [Table_1]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:AConnectionString %>"
SelectCommand="SELECT * FROM [Table_1] where theID=@theID">
<SelectParameters>
<asp:ControlParameter Name="theID" ControlID="GridView2" PropertyName="SelectedValue" />
</SelectParameters></asp:SqlDataSource>
</div>
</form>
</body>
</html>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;namespace WebApplication5
{
public partial class WebForm3 : System.Web.UI.Page,ICallbackEventHandler
{
protected string temp;
public void RaiseCallbackEvent(string eventArgument)
{
this.GridView2.SelectedIndex = Convert.ToInt32(eventArgument);
this.DetailsView1.DataBind();
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
DetailsView1.RenderControl(htmlWrite);
temp = stringWrite.ToString();
}public string GetCallbackResult()
{
return temp;
}
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.GetCallbackEventReference(this, "param", "handleResultFromServer", "context");}
}
}BTW if you have new problem please start a new thread.
Thanks
Sincerely,
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |