<asp:GridView ID="GridView1" runat="server" 
AllowPaging="True"
AutoGenerateColumns="False"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound"
PageSize="10" 
Width="733px"
TabIndex="2";>
<Columns;>
     <asp:BoundField HeaderText="Sr. No";>
   <ItemStyle HorizontalAlign="Center" /;>
     </asp:BoundField;>
     <asp:TemplateField HeaderText="CityId" Visible="False";>
       <EditItemTemplate;>
      <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CityId") %>'></asp:TextBox;>
        </EditItemTemplate;>
        <ItemTemplate;>
       <asp:Label ID="lblCityId" runat="server" Text='<%# Bind("CityId") %;>';></asp:Label;>
        </ItemTemplate;>
    </asp:TemplateField;>
    <asp:BoundField DataField="CountryName" HeaderText="Country" /;>
    <asp:BoundField DataField="StateName" HeaderText="State" /;>
</Columns;>
  
CS code...
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = Convert.ToString(GridView1.PageIndex * GridView1.PageSize + SrNo);
            SrNo++;
        }
    }
public void GridViewBind()
    {
        SqlConnection conn = new SqlConnection(connectionString);
        Ds = SqlHelper.ExecuteDataset(myconn, "usp_CityMaster");
        GridView1.DataSource = Ds;
        GridView1.DataBind();
    }
 protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        CityBind();
    }
Thanks & Regards 
Santosh Singh






0 comments:
Post a Comment