开发者

click event for a individual cells in gridview

开发者 https://www.devze.com 2023-02-21 16:44 出处:网络
I am working with asp.net3.5 c#. I want to make the click event for a cell in a GridView. I\'m actually using a DataTable and a开发者_如何学Pythonssign this to GridView.

I am working with asp.net3.5 c#. I want to make the click event for a cell in a GridView. I'm actually using a DataTable and a开发者_如何学Pythonssign this to GridView.

I want click event for a cell. Is it possible? If it is possible please guide me how to solve that please.


You would have to register a click event for the cell which would post it back to server for your processing.Found Thiswhich might help you in achieving the cell click

Here its been done by adding the onclick attribute to the cell in the RowDataBound Event, I am not entirely sure if this is what you want but might be helpful.


Hi you can solve this by this code:

something along these lines

I assumed you are having a button in each row of the grid view and you want to know on which row you clicked the button and retrieve the value of another particular cell on the same row on which this button is associated:

 protected void Downloadbtn_Click(object sender, EventArgs e)
    {
        Button clickedButton = sender as Button;
        GridViewRow clickedGridViewRow = (GridViewRow)clickedButton.Parent.Parent;
        string x = clickedGridViewRow.Cells[AnotherCellNumberInTheSameRowWhoseValueYouWantToGet].Text;
     }

And you can associate button in each gridview row by having this code in .aspx page where gridview is present

                 <Columns>
                        <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Button ID="Downloadbtn" Text="Download" runat="server" OnClick="Downloadbtn_Click"></asp:Button>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>

And you want to make AutoGenerateColumns property of Grid view to be true

I hope this answers your question

0

精彩评论

暂无评论...
验证码 换一张
取 消