Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

I have a detailview and i want to use onClick Event of the button used in detailsView, Is there any way?
Second, how to get the particular datamember( like IDNo ) from the detailsView and put the value in some string?

Like if i have a detail view containing (IDNo, School, College, University, (a buttonfield) and if the buttonfield is clicked then it gets the IDNo from the detailView

Any help ?
Posted

You can use OnItemCommand event of detailsview after that give the CommandName of that button ,in behind in that that event you can that CommandName like

C#
if(e.CommandName == "xyz")
{

// you logic
}
 
Share this answer
 
v2
Comments
saad_lah 26-Jul-13 11:14am    
where is CommandName supposed to be??
Like the DetailsView object(People) then DetailsView.Commandname??
Asp_Learner 26-Jul-13 11:59am    
refer below link

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.itemcommand.aspx
Here is a sample try this

XML
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
        AutoGenerateColumns="False" DataKeyNames="ProductID"
        DataSourceID="SqlDataSource1" onrowdatabound="GridView1_RowDataBound">
        <Columns>
            
            <asp:BoundField DataField="ProductID" HeaderText="ProductID"
                InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
            <asp:BoundField DataField="ProductName" HeaderText="ProductName"
                SortExpression="ProductName" />
            <asp:TemplateField HeaderText="del">
                <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>


Code behind

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;
        int index = gvr.RowIndex;
        string value = GridView1.Rows[index].Cells[1].Text;
    }
 
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