Showing posts with label Gird View Example. Show all posts
Showing posts with label Gird View Example. Show all posts
First desing the page like following way
<table border="2">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Product Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Product
Name Required" Text="*" ControlToValidate="TextBox1" ValidationGroup="val1"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ErrorMessage="Enter
valid product name" ControlToValidate="TextBox1" ValidationExpression="[a-zA-Z ]+" ValidationGroup="val1"></asp:RegularExpressionValidator>
</td>
First Design The page take one Gridview.
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox2_CheckedChanged"
/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("id")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
First Design The Page like following way take one Gridview and One Button for Delete
The Following is .aspx page design
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox2_CheckedChanged"
/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("id")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Following is the .aspx file code write this first. . .
<script type="text/javascript">
function showNestedGridView(obj) {
var nestedGridView = document.getElementById(obj);
var imageID = document.getElementById('image' + obj);
if (nestedGridView.style.display == "none") {
nestedGridView.style.display = "inline";
imageID.src = "minus.png";
} else {
nestedGridView.style.display = "none";
imageID.src = "plus.png";
}
}
</script>
<br />
<br />
<br />
<center>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
DataKeyNames="pid" ShowFooter="True"
onrowdatabound="GridView1_RowDataBound"
onrowcommand="GridView1_RowCommand">
<Columns>
<script type="text/javascript">
function showNestedGridView(obj) {
var nestedGridView = document.getElementById(obj);
var imageID = document.getElementById('image' + obj);
if (nestedGridView.style.display == "none") {
nestedGridView.style.display = "inline";
imageID.src = "minus.png";
} else {
nestedGridView.style.display = "none";
imageID.src = "plus.png";
}
}
</script>
<br />
<br />
<br />
<center>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
DataKeyNames="pid" ShowFooter="True"
onrowdatabound="GridView1_RowDataBound"
onrowcommand="GridView1_RowCommand">
<Columns>
First of all you have to create sql
connection with the database...
For this see the following link
now use the following code for gridview bind in button click event...
protected void Button1_Click(object
sender, EventArgs e)
{
{
con.open();
SqlDataAdapter adp=new SqlDataAdapter("Select * from Emp",con);
DataTable dt=new DataTable();
adp.Fill(dt);
GridView1.DataSource=dt;
GridView1.Databind();
}
