Hi All

I have datagrid with a dopostback javascript, right now it looked click-able, when I hover with a mouse it select the entire row, except one thing when I click it doesnt do anything, I need to select a row in my datagrid and pass the values of the row selected and clicked into another form, which is EDIT, I dont wana use Select, Edit and delete commands

Anyone knows how can I achieve this and which datagrid event handler should I use if needed be

Thanks in advance

Is there a chance of using hyper link? One or all your columns could be hyperlinks and the link itself would be something like

<a href='newWebForm.aspx?key=' <%= bind-key %>'>your column data</a>

Other is, since you are handling color change to show current selected row, you are already handling atleast one mouse event. Same way, you can handle click event in JavaScript. I guess I am missing something; don't know what.

Let us know your solution when you close the thread.

I have ItemCreated event handler and inside it I have the below code I got this from internet which changes the row color of my datagrid, when hovered

if (e.Item.ItemType == ListItemType.AlternatingItem)
        {
            e.Item.Attributes.Add("onmouseover",
                   "this.style.backgroundColor='beige';this.style.cursor='pointer'");
            e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#99B3FF';");
            e.Item.Attributes.Add("onclick", "javascript:__doPostBack" +
                   "('_ctl0$DataGrid1$_ctl" +
                   ((Convert.ToInt32(e.Item.ItemIndex.ToString())) + 2) +
                   "$_ctl0','')");
        }

and then I have this code inside the same event handler which should be passing the values to another form but its not doing anything, and now I am a bit confused, because I dont only need to bind one value into my EditForm and I dont wish to use the select commands, can u elaborate ur answer a bit further, with a complete example maybe

it looks like you got onclick handled. This should be submitting to the same page. I was suggesting more like following:
1. Under <head> add following javascript function:

function callPage(Rowkey) {
  alert ('debug: key=' + Rowkey);
  window.location = "yourOtherPage.aspx?key=' + Rowkey;
}

2. In your current code, replace onClick part as following:

e.Item.Attributes.Add("OnClick", "javascript:callPage ('" + your_key_as_per_row + "')");

The way I have used it is in my project is one cell itself is href. You seem to be doing the whole row clickable. If your alert works, there is hope. As you would notice, "your_key_as_per_row" is your business logic, not just row number (it could be row number if logically that is sufficient).

Here is actual sample code from my project

hlnk.Attributes.Add("OnClick", "OpenWeekRpt('Reports/TestDDL.aspx?showMenu=N&periodID=" + ddlPeriod.SelectedValue
                + "&metCode=" + dr["metricsID"].ToString() + "&SRcode=" +ddlCountryRel.SelectedValue+ "')");

Here hlink is one cell.

As you would notice, there are number of things being passed in the URL (string), the URL is parameter to javascript function: OpenWeekRpt.

Hope this helps.

commented: Thanks man +2

Wow, thanks Dude, its working, thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.