3
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by vuyiswamb
0

1. Create template columns to display textboxes and CheckBoxes in the GridView.
2. If you bind the GridView with a DataTable which is filled with records from a database, check if the DataTable has any rows. If it has no rows, add an empty record to the DataTable and then bind it with GridView. Note that the DataTable does not have constrains like AllowDBNull set to true before adding an empty row.

0

use Template Fields like this

<asp:GridView ID="MYGRid" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateField >
    <ItemTemplate>
     <asp:CheckBox ID="ID" runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
    
    <asp:TemplateField HeaderText ="Name">
    <ItemTemplate>
    <asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
   
    <asp:TemplateField HeaderText ="Mobile Number">
    <ItemTemplate>
    <asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    
    <asp:TemplateField HeaderText ="Age">
    <ItemTemplate>
    <asp:TextBox ID="textbox3" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    
    <asp:TemplateField HeaderText ="Gender">
    <ItemTemplate>
    <asp:DropDownList ID="dropdown1" runat="server"></asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateField>
    
    <asp:TemplateField HeaderText ="City">
    <ItemTemplate>
    <asp:TextBox ID="textbox4" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    
    <asp:TemplateField HeaderText ="City">
    <ItemTemplate>
   <asp:Button ID="button1" Text="Add" runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    
    </asp:GridView>

on the Databound Event Bind the ComboBox to the Female and Male.

Hope this Helps

0

I want to develop a Phonebook application .Suppose initially as when the number of records in DB is zero,Den I want just to have one row in Gridview that contains textboxes & dropdown & in pic. Now suppose When the user add one record & click on add Button,Dat record is added in gridview & first row is same that contains textboxes & other controls.

hey tell me ,if the number is of records are large then everytime if we bind the DB to Gridview,it takes times,There is no such procedure to add the records in Grdiview widout binding again.

hi vuyiswamb,tell me one thing,suppose first time textboxes & dropdown controls are there in first row.Now suppose user add records.After one record is added,now that row wid textnoxes & dropdown controls will be there again in the Gridview.

Edited by sandeep_1987: n/a

0

Good Day sandeep_1987

sandeep_1987 wrote :

I want to develop a Phonebook application .Suppose initially as when the number of records in DB is zero,Den I want just to have one row in Gridview that contains textboxes & dropdown & in pic. Now suppose When the user add one record & click on add Button,Dat record is added in gridview & first row is same that contains textboxes & other controls.

You dont allows need agridview to add data into the Table, you can use a normal page with Textboxes and Validate whatever you want before you send the data to the Database, Consider that option.

sandeep_1987 wrote :

hey tell me ,if the number is of records are large then everytime if we bind the DB to Gridview,it takes times,There is no such procedure to add the records in Grdiview widout binding again.

if you add Paging in your Gridview the Records will not all be shown at the same time. Look at this article Regarding that

How to do Paging in a Gridview

sandeep_1987 wrote :

hi vuyiswamb,tell me one thing,suppose first time textboxes & dropdown controls are there in first row.Now suppose user add records.After one record is added,now that row wid textnoxes & dropdown controls will be there again in the Gridview.

I now see what you want Exactly. a Gridview will automatically create a Textbox to edit data if you want to edit data. Look at this two articles, if you dont understand tell me i will explain better


http://www.dotnetfunda.com/articles/article18.aspx


http://www.codeproject.com/KB/cs/N-Tier22.aspx

http://www.codeproject.com/KB/cs/NTier.aspx

Hope this Helps

Kind Regards

Vuyiswa Maseko

0

hi vuyiswamb,first of all Thx for the Reply. I dont want that .To Add Record I want that first row in the Grdiview should always be a row that contains textboxes & other Controls.

Secondly, Edit or Delete Operations are same as are there in http://www.dotnetfunda.com/articles/article18.aspx
,But can u tell me is it possible to edit or Delete using JS,widout refreshing the part,Because events like OnRowEditing and OnRowUpdating will refresh the page when they are called

0

Dont Worry about the REfreshing, add the Grid into an Update Panel to remove the Page Flickers

sandeep_1987 wrote :

hi vuyiswamb,first of all Thx for the Reply. I dont want that .To Add Record I want that first row in the Grdiview should always be a row that contains textboxes & other Controls.

mmh i see what you are Saying. It can be done ,but there another way that the Gridview do for you, at the End of each grid, if you click an insert Button on the grid, it adds a New empty place where you can add the Record. The checkboxes and the Dropdown will still persist.

Kind Regards

Vuyiswa Maseko

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.