Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
Is there any way to select the item in gridview without the select button. Plz help

I tried this code
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType == DataControlRowType DataRow) 
{ 
e.Row.Attributes["OnClick"] = ClientScript.GetPostBackEventReference(this, "Select$" + e.Row.RowIndex); 
}

but not going to the selected index changing event

Thanks in advance
Nidhin
Posted
Updated 19-Feb-10 0:54am
v3

You had attached wrong event. Try this:

C#
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
     e.Row.Attributes["onclick"] =
     ClientScript.GetPostBackClientHyperlink(this.myGridView, "Select$" + e.Row.RowIndex);
   }
}


Each row will then behave like a link.
 
Share this answer
 
Do you want this? when you are going to check checkbox then all rows to be selected.

use this javascript
<pre>
function headerchk(id)
{
var state = document.getElementById(id).checked;
chkSelect(state)
}

function chkSelect(state)
{
var grd= document.getElementById("<%= grvList.ClientID %>");
var varCell;//this cell contains the value of cell
if (grd.rows.length > 0)
{
for (i=0; i<grd.rows.length; i++)
{
cell = grd.rows[i].varCell[0];
for (j=0; j<varCell.childNodes.length; j++)
{
if (varCell.childNodes[j].type =="checkbox")
{

varCell.childNodes[j].checked = state;
}
}
}
}
}
</pre>
ASPX Code
<pre>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" onclick="headerchk(id)" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</pre>

if you click on checkbox in header then it will call headerchk() then it will pass the status of checkbox to chkSelect() if checked tthen select all and if unchecked then select none
 
Share this answer
 
hi,

i dint get your que
by the way if i got que properly that there is no need of select button..
Explain ur que properly realm what u wanna do.
 
Share this answer
 

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