Home
Products
Forums
Help
Publish Article
Go Freelance

How to raise gridview server side event when when row is selected

Downloads

If you are seeing this section and do not see download links, this means that you are not logged into our site. If you already are a member, click on the login link and login into site and come back to this page for downloading the control files. If you are not a member, click on registration link to become a Winista member and download the control for free.

In this article I will be discussing how you can raise a server side event when a user selects a row in gridview. This is not the same event that gets raised when user selects a row for editing data. This is the same problem that I talked about in my previous article How to highlight gridview row when row is selected.

Row Click Event And Client Side Javascript

All the discussion from previous article How to highlight gridview row when row is selected applies here too. Its the same technique to handle click event.

Raising Server Side Event

<script language="javascript" type="text/javascript">
var gridViewCtlId = '<%=ctlGridView.ClientID%>';
function onGridViewRowSelected(rowIdx)
{
     __doPostBack(gridViewCtlId, rowIdx);
}

function __doPostBack(eventTarget, eventArgument) {
    var theform = document.form1;
 	theform.__EVENTTARGET.value = eventTarget;
 	theform.__EVENTARGUMENT.value = eventArgument;
 	theform.submit();
}
</script>							
							

Handling Server Side Event

protected void Page_Load(object sender, EventArgs e)
{
    getProducts();
    if (!IsPostBack)
    {
        bindGridView();
    }
    else
    {
        object obTarget = this.Request.Form["__EVENTTARGET"];
        object obArg = this.Request.Form["__EVENTARGUMENT"];
        if (null != obArg)
        {
            int rowIdx = Int32.Parse(obArg.ToString());
            OnRowSelected(rowIdx);
        }
    }
}							
							

You can download the sample project and play with it to see how this works.

Go Freelance
Home     About us     Contact us    Copyright    Privacy Policy    Return Policy    Advertisers
Copyright © Netomatix