Thursday, 18 October 2012

datakey on gridview on rowdatabound , rowdeleteing, rowupdating, selectindexchanging in asp.net c#



**By which we can add same button in every rows with links (Events=>On GridView1_RowCommand)...
-------------------------------------------------
ON cs:------>
----------------------------------------------------------
===============================================================================

     string id = GridView1.DataKeys[e.NewEditIndex].Value.ToString();
=============================================================================

================================================================================

 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
            Gridbind();
        }


=========================================================================================

  subGroup.Code = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["Code"].ToString());
  subGroup.SubGroupName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
  subGroup.AcMGroupID = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text);

=========================================================================================

.......................................................................
       ----------------------------->DK Uses.

.......................................................................
        string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        Session["St_UserID"] = id;
        Response.Redirect("Payout_Statement_New.aspx");

.........................................................................



protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int index = Convert.ToInt32(e.CommandArgument);
        string Guid = GridView1.DataKeys[index].Values["UserID"].ToString();

        Response.Redirect("Tree.aspx?ID="+Guid);

    }

-------------------------------------------------
ON cs:------>
----------------------------------------------------------
string cn= e.CommandName;
       if (cn != "Page")
       {
           int index = Convert.ToInt32(e.CommandArgument);
           string Guid = GridView1.DataKeys[index].Values["sno"].ToString();
           Session["sno"] = Guid;
           ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( 'Readmessage.aspx', null, 'height=500,width=750,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes' );", true);
       }
-------------------------------------------------
ON SOURCES:------>
-------------------------------------------------------

<asp:GridView id="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" PageSize="50" Font-Size="10pt" Font-Names="Verdana" AllowPaging="True" AutoGenerateSelectButton="True" CellPadding="4" OnPageIndexChanging="GridView1_PageIndexChanging" BackColor="White" BorderColor="#336666" BorderWidth="3px" AutoGenerateColumns="False" BorderStyle="Double" OnRowCommand="GridView1_RowCommand" DataKeyNames="UserID">

--------------------------------------------
ON SOURCES:------>
-------------------------------------------------
<asp:GridView id="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="UserID" OnRowCommand="GridView1_RowCommand" BorderStyle="Double" AutoGenerateColumns="False" BorderWidth="3px" BorderColor="#336666" BackColor="White" OnPageIndexChanging="GridView1_PageIndexChanging" CellPadding="4" AutoGenerateSelectButton="True" AllowPaging="True" Font-Names="Verdana" Font-Size="10pt" PageSize="50">
<FooterStyle BackColor="White" ForeColor="#333333"></FooterStyle>
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID"></asp:BoundField>
<asp:BoundField DataField="UserName" HeaderText="User Name"></asp:BoundField>
<asp:BoundField DataField="SponserID" HeaderText="SponsorID"></asp:BoundField>
<asp:BoundField DataField="DOJ" HeaderText="Date Of Joining"></asp:BoundField>
<%--<asp:BoundField DataField="LCount" HeaderText="LeftCount"></asp:BoundField>
<asp:BoundField DataField="RCount" HeaderText="RightCount"></asp:BoundField>--%>
<asp:ButtonField Text="Geneology">
<ItemStyle BackColor="Silver" ForeColor="Navy"></ItemStyle>
</asp:ButtonField>
</Columns>
<RowStyle BackColor="Silver" ForeColor="#333333"></RowStyle>
<EmptyDataTemplate>
<span style="color: #000066">
<strong><span style="font-size: 16pt"><span>
No Data Found
!!!!</span></span></strong></span>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#339966" ForeColor="White" Font-Bold="True"></SelectedRowStyle>
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center"></PagerStyle>
<HeaderStyle BackColor="#336666" ForeColor="White" Font-Bold="True"></HeaderStyle>
</asp:GridView>
-------------------------------------------------------------------------------------

1 comment:

  1. how to link between RowUpdating and RowDataBound in gridview pls any one say.. my mail Id arunjun6@gmail.com

    ReplyDelete