On button click select row in gridview

Posted by Navalemanoj0405 under Regular Expressions on 5/9/2011 | Points: 10 | Views : 42454 | Status : [Member] | Replies : 4
Dear All


I want to get select a row when i click on button in gridview

this is my code:

<asp:GridView ID="grdvwIndiMemSlab" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" Width="457px" OnRowDataBound="grdvwIndiMemSlab_RowDataBound"
OnRowCommand="grdvwIndiMemSlab_RowCommand" GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<HeaderStyle BorderWidth="1" VerticalAlign="top" />
<ItemStyle Width="50px" BorderWidth="1" VerticalAlign="Top" />
<ItemTemplate>
<asp:LinkButton runat="server" CommandName='<%#Eval("ExpectedDate") %>' ID="btnSelect"
CommandArgument='<%#Eval("MemberID") %>' Text="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />

</asp:GridView>



but not working it please help me.

thanks...




Responses

Posted by: Susanthampy on: 5/9/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Pls refer this link,

http://www.codeproject.com/Questions/193467/On-button-click-select-row-in-gridview.aspx

Regards,
Susan

Navalemanoj0405, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Walia_jagwinder on: 5/9/2011 [Member] Starter | Points: 25

Up
0
Down
Simply Write

OnClick="functionname"

One person's data is another person's program.

Navalemanoj0405, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 5/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
The button on which you want to select a particular row add OnClick event, in your case

<ItemStyle Width="50px" BorderWidth="1" VerticalAlign="Top" />
<ItemTemplate>
<asp:LinkButton runat="server" CommandName='<%#Eval("ExpectedDate") %>' ID="btnSelect" CommandArgument='<%#Eval("MemberID") %>' Text="Select" OnClick="select_click"
></asp:LinkButton>
</ItemTemplate>

Then in page code behind

public void select_click(object sender, EventArgs e)
{
GridViewRow selectedRow = ((Control)sender).Parent.NamingContainer as GridViewRow;
grdvwIndiMemSlab.SelectedIndex = selectedRow.RowIndex;
}

Thanks,
Debata

Navalemanoj0405, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 5/10/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Navalemanoj0405


u want to feth data on Selected row . . So Firstly Set Property AutoGenratedSelecteButton = True

then on double click in Gridview on SelectIndexChanged Event Write This Code . .

    protected void gv1_SelectedIndexChanged(object sender, EventArgs e)

{
GridViewRow row = gv1.SelectedRow;
txtfldname.Text = row.Cells[3].Text;
}


Best Regard's
Prabhakar

Navalemanoj0405, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response