I am so frustrated. Using asp.net GridView. Using a LinkButton with the CommandName="Delete". Don't understand why the page isn't posting back. I've done this a million times in other apps. I've compared them against one another and nothing appears different. I will preface by saying this IS someone else's template, however, so it's not my same template.
Any ideas what might be causing my issues?
My scenario is this:
ASPX Page (edited to add the HTML; there's more HTML in the site.Master and there's also a tag for the AjaxControlToolkit at the top of the page):
<div class="width80 container body-content">
<h2 class="marginTop50">Message Board</h2>
<asp:Panel ID="pnlMsgsForUser" runat="server" Visible="false">
<div class="jumbotronSmallFont">
<asp:Label ID="lblErrorMessage" CssClass="has-error" runat="server"></asp:Label>
</div>
</asp:Panel>
<div class="jumbotronSmallFont">
<h4>New Message</h4>
<form>
<div class="form-group">
<label for="messageBody">Message Body</label>
<textarea class="form-control" id="messageBody" rows="3" style="max-width: 600px;"></textarea>
</div>
<div class="text-center">
<button id="btnSave" class="btn btn-primary" style="width: 75px;">Save</button>
<button type="button" id="btnReset" class="btn btn-default marginLeft15px" style="width: 75px;">Reset</button>
</div>
</form>
</div>
<div>
<asp:GridView ID="gvMessages" runat="server" Width="100%"
CssClass="table adminMessageBoardTable marginAuto" AutoGenerateColumns="False"
OnRowUpdating="gvMessages_RowUpdating"
OnRowCancelingEdit="gvMessages_RowCancelingEdit"
OnRowDataBound="gvMessages_RowDataBound"
OnRowEditing="gvMessages_RowEditing"
OnRowDeleting="gvMessages_RowDeleting"
DataKeyNames="Id" BorderStyle="NotSet">
<Columns>
<asp:TemplateField HeaderText="Message" HeaderStyle-CssClass="center" SortExpression="Message">
<EditItemTemplate>
<asp:TextBox ID="txtMsg" Width="100%" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("MessageBody") %>' ID="lblMessage"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Updated" SortExpression="DateUpdated" HeaderStyle-CssClass="center" ItemStyle-CssClass="center">
<HeaderStyle Width="120px" />
<EditItemTemplate>
<asp:Label runat="server" ID="lblEditDateUpdated" Enabled="false"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("DateUpdated","{0:d}") %>' ID="lblDateUpdated"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Updated By" SortExpression="UpdatedBy" HeaderStyle-CssClass="center" ItemStyle-CssClass="center">
<HeaderStyle Width="120px" />
<EditItemTemplate>
<asp:Label runat="server" Text="" ID="lblEditUpdatedBy" Enabled="false"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("UpdatedBy") %>' ID="lblUpdatedBy"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="center">
<HeaderStyle Width="120px" />
<EditItemTemplate>
<asp:LinkButton ID="lbUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"
OnClientClick="return confirm('You are about to update this entry. \n\nDo you wish to proceed?');"></asp:LinkButton>
<asp:LinkButton ID="lbCancel" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="lbDelete" runat="server" CommandArgument='<%# Eval("Id") %>' CausesValidation="False"
CommandName="Delete" Text="Delete" OnClientClick="return confirm('You are about to delete this entry. \n\Do you wish to proceed?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
In my code-behind, I have:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var user = CommonFunctions.GetUserID(true);
var Admin = Roles.IsUserInRole(user, "Administrator");
var Dev = Roles.IsUserInRole(user, "Developer");
if (!Admin && !Dev)
{
Response.Redirect("~/");
}
gvBind(true);
}
}
When I click on the Delete linkbutton for a row, it drops into the Page_Load and
!Page.IsPostBack
verifies as true. I have no idea why it's doing this. It also never even hits the RowDeleting command. My breakpoint is so sad.
In my other app, all the markup and code-behind are pretty much the same. The only differences are the gridview name and the Eval tags. But when I click Delete in that app, it skips the !Page.IsPostBack section. :( It also obviously fires the RowDeleting.
I've also tried implementing RowCommand, but that event never fires either. It only does Page_Load and RowDataBound before essentially refreshing the page.
Any ideas?
Please, and thanks!!!
Your code is working fine. When I click Delete button, it triggers gvMessages_RowDeleting event. Here is how I test it -
<asp:GridView ID="gvMessages" runat="server" Width="100%"
CssClass="GridView marginAuto" AutoGenerateColumns="False"
OnRowDeleting="gvMessages_RowDeleting"
DataKeyNames="Id">
<Columns>
<asp:TemplateField HeaderText="Message" HeaderStyle-CssClass="center" SortExpression="Message">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("MessageBody") %>' ID="lblMessage"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="center">
<ItemTemplate>
<asp:LinkButton ID="lbDelete" runat="server" CommandArgument='<%# Eval("Id") %>' CausesValidation="False"
CommandName="Delete" Text="Delete"
OnClientClick="confirm('You are about to delete this entry. \n\Do you wish to proceed?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code Behind
public class Item
{
public int Id { get; set; }
public string MessageBody { get; set; }
}
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvMessages.DataSource = new List<Item>
{
new Item {Id = 1, MessageBody = "One"},
new Item {Id = 2, MessageBody = "Two"},
new Item {Id = 3, MessageBody = "Three"},
};
gvMessages.DataBind();
}
}
protected void gvMessages_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
}
OnClientClick="return confirm('Are you sure?');"
Try to add the return from your confirm statement.
Related
<div>
<table>
<tr>
<td>
<asp:Label runat="server" text="Search"></asp:Label>
</td>
<td>
<asp:TextBox runat="Server" placeholder="Enter EmpId" id="txtSearch">
</asp:TextBox>
</td>
<td>
<asp:Button ID="btnGo" runat="server" Text="Go" onclick="btnGo_Click"/>
</td>
<td>
<asp:Button ID="btnShowAll" runat="server" Text="ShowAll"
onclick="btnShowAll_Click" />
</td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="EmpId" DataField="EmpId"/>
<asp:BoundField HeaderText="Employee Name" DataField="EmpName"/>
<asp:BoundField HeaderText="Designation" DataField="EmpDesgn"/>
<asp:BoundField HeaderText="Salary" DataField="Sal"/>
<asp:TemplateField HeaderText="Salary Status">
<ItemTemplate>
<asp:Button runat="Server" id="btnPay" text="Pay" CommandName="Pay"
Visible='<%#Eval("Status").Equals("Paid")?false:true %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
I want to pay the salary of unpaid employees on clicking the pay button as pay button is showing only for unpaid salaries.
You can do this using OnRowCommand event. Add the event handler to the gridview
OnRowCommand="GridView1_RowCommand"
Bind the command argument to your button
<asp:TemplateField HeaderText="Salary Status">
<ItemTemplate>
<asp:Button runat="Server" id="btnPay" text="Pay" CommandName="Pay"
Visible='<%#Eval("Status").Equals("Paid")?false:true %>'
CommandArgument = '<%#Eval("EmpId")%>'
/>
</ItemTemplate>
</asp:TemplateField>
Then in the RowCommand event you can catch the EmpId from the command argument, pay the salary and rebind the grid view
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="Pay")
{
// get the command argument.
string empId = e.CommandArgument as string;
//you code here to pay the salary
//ReBind Gridview to refresh
}
}
I am new to ASP.NET. I am trying to insert a item into a dropdownlist when click "New" to add new record. which the form will switch from ItemTemplate to InsertTempplate
Error:
"System.NullReferenceException: Object reference not set to an
instance of an object."
this code in my DetailsView.
<ItemTemplate>
<asp:Label ID="lblVendorName"
runat="Server" style="text-align:left; width:100%"
Text='<%# Eval("VendorName")%>' Width="70%"/>
</ItemTemplate>
<InsertItemTemplate>
<asp:DropDownList id="insertVendorName" datasourceid="VendorSqlDataSource"
datatextfield="VendorName" DataValueField="VendorID"
OnSelectedIndexChanged="ddlVendor_SelectedIndexChanged"
runat="server" AutoPostBack="true" />
<asp:SqlDataSource ID="VendorSqlDataSource"
ConnectionString="<%$Connectionstrings:ConnectionString%>"
SelectCommand="SELECT VendorID, VendorName
from MDF_Vendor" runat="server">
</asp:SqlDataSource>
</InsertItemTemplate>
Updated... Below is set of Link Bottons.
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server"
CommandName="Edit" Text="Edit"/> |
<asp:LinkButton ID="btnInsert" runat="Server"
Text="New" CommandName="New"
OnClick="LinkButton_Click" /> |
<asp:LinkButton ID="btnDelete"
runat="server"
CommandName="Delete" Text="Delete" /> |
</ItemTemplate>
<InsertItemTemplate>
<asp:LinkButton ID="btnInsert" runat="Server"
Text="Insert" CommandName="Insert"/>
<asp:LinkButton ID="btncancel" runat="server"
CommandName="Cancel" Text="Cancel"/>
</InsertItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="btncancel" runat="server"
CommandName="Cancel" Text="Cancel"/>
</EditItemTemplate>
</asp:TemplateField>
I tried this code below suggested by #Aghislas (Thanks!)
protected void LinkButton_Click(object sender, EventArgs e)
{
DropDownList ddlVendor = (DropDownList)DetailsView1.FindControl("insertVendorName");
ddlVendor.Items.Insert(0, new ListItem("---Select---", "-1"));
}
Please help. Thank you.
You can try with this code
<asp:LinkButton id="LinkButton1"
Text="Click Me"
OnClick="LinkButton_Click"
runat="server"/>
protected void LinkButton_Click(Object sender, EventArgs e)
{
var ddlVendor =(DropDownList)DetailsView1.FindControl("insertVendorName");
ddlVendor.Items.Insert(0, new ListItem("---Select---", "-1"));
}
Nota : You delete code in the Page_Load and move in Click delegate
I am trying to update a TextBox within currently edited row within a GridView on when changing items on a DropDownList and I cant quite get it going in VB. I found this code in c# but don't know if I'm on the right track?
Can you please offer some help?
PS: This code is for an OnMouseOver event but the point is to update the TextBox while in edit mode.
<ItemTemplate>
<asp:TextBox runat="server" ID="tx1" onmouseover='<%# "ChangeValue(" +((DataGridItem)Container).FindControl("tx1").ClientID + ")"%>'></asp:TextBox>
</ItemTemplate>
JS Code:
function ChangeValue(i)
{
var t=i.id
document.getElementById(t).value="Hello World!";
}
Try the following:
Put the following script in head tag:
<script language="javascript" type="text/javascript">
function ChangeValue(ddl,txtid)
{
var txt=document.getElementById(txtid);
var dval= ddl.options[ddl.selectedIndex].value;
if(dval=="1")
{
txt.value="It's 1";
}
if(dval=="2")
{
txt.value="It's 2";
}
if(dval=="3")
{
txt.value="It's 3";
}
}
</script>
Try the gridview below:
<asp:GridView ID="GridView1" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
AutoGenerateColumns="false" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowCommand="GridView1_RowCommand"
runat="server" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:CommandField ButtonType="link" ShowEditButton="true" ShowCancelButton="true" />
<asp:TemplateField HeaderText="CategoryID">
<ItemTemplate>
<asp:LinkButton ID="lnkID" runat="server" CommandName="sel" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.CategoryID") %>'
Text='<%# DataBinder.Eval(Container,"DataItem.CategoryID") %>'></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl" runat="server">
<asp:ListItem Text="1" Value="1" Selected="true"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.CategoryID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtComments" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryName">
<ItemTemplate>
<asp:LinkButton ID="lnkName" runat="server" CommandName="sel" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.CategoryName") %>'
Text='<%# DataBinder.Eval(Container,"DataItem.CategoryName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Handle the rowcreated event in codebehind:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("ddl");
TextBox txt = (TextBox)e.Row.FindControl("txtComments");
txt.Text = "It's 1";
//------------ Set onchange function for dropdown---------------------------//
ddl.Attributes.Add("onchange", "javascript:ChangeValue(this,'" + txt.ClientID + "');");
}
}
Bind the grid with Categories table in northwind db.
I have a GridView which supports deleting. I'd like to add a pop up window with a question like 'Are you sure you want to delete this row?'.
My code:
<asp:GridView id="GridAccounts" runat="server" AutoGenerateColumns="False"
ShowFooter="True" DataKeyNames="ID"
DataSourceID="AccountDataSource" onrowcommand="GridAccounts_RowCommand">
<SelectedRowStyle BackColor="Lime" />
<Columns>
<asp:CommandField ButtonType="Image" ShowDeleteButton="True" DeleteImageUrl="~/Pictures/delete.jpg" />
<asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="ID">
<EditItemTemplate>
<asp:Label ID="LabelAccountIDUpdate" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="ButtonAccountIDInsert" runat="server" CommandName="Insert" Text="Insert" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="LabelAccountID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code behind:
protected void GridPaymentMethod_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton deleteButton = (ImageButton)e.Row.Cells[0].Controls[0];
MyMoney.PaymentMethodRow row = (MyMoney.PaymentMethodRow)((System.Data.DataRowView)e.Row.DataItem).Row;
deleteButton.OnClientClick = string.Format("return confirm('Are you sure you want to delete payment method {0}?');", row.Name.Replace("'", #"\'"));
}
}
This renders as:
<input type="image" src="Pictures/delete.jpg" alt="Delete" onclick="return confirm('Are you sure you want to delete payment method Gotovina?');javascript:__doPostBack('ctl00$MainContent$GridPaymentMethod','Delete$0')" style="border-width:0px;" />
If I click OK on confirmation window, postback occurs, but nothing happens. If I comment out RowDataBound code, than delete works OK. Code whithout confirmation pop up:
<input type="image" src="Pictures/delete.jpg" alt="Delete" onclick="javascript:__doPostBack('ctl00$MainContent$GridPaymentMethod','Delete$0')" style="border-width:0px;" />
What am I doing wrong?
I believe this is an example of what you are trying to do. It's cleaner and you don't have to go nutz with the code behind.
In your code you must change ButtonType="Image" to ButtonType="Link" - then onclick="..." will be rendered without javascript:___doPostBack(...) part. And in the GridPaymentMethod_RowDataBound event set something like deleteButton.Text = "<img src=\"path_to_image\" ... />" (use html entities instead of <>).
Or you can use ImageButton with ComamndName="delete" and ConfirmButtonExtender from ASP.NET AjaxToolkit suite.
deleteButton.OnClientClick = string.Format("((!confirm('Are you sure you want to delete payment method {0}?'))?return false);", row.Name.Replace("'", #"\'"));
I'm trying to get an ASP.NET 3.5 GridView to show a selected value as string when being displayed, and to show a DropDownList to allow me to pick a value from a given list of options when being edited. Seems simple enough?
My gridview looks like this (simplified):
<asp:GridView ID="grvSecondaryLocations" runat="server"
DataKeyNames="ID" OnInit="grvSecondaryLocations_Init"
OnRowCommand="grvSecondaryLocations_RowCommand"
OnRowCancelingEdit="grvSecondaryLocations_RowCancelingEdit"
OnRowDeleting="grvSecondaryLocations_RowDeleting"
OnRowEditing="grvSecondaryLocations_RowEditing"
OnRowUpdating="grvSecondaryLocations_RowUpdating" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblPbxTypeCaption" runat="server"
Text='<%# Eval("PBXTypeCaptionValue") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlPBXTypeNS" runat="server"
Width="200px"
DataTextField="CaptionValue"
DataValueField="OID" />
</EditItemTemplate>
</asp:TemplateField>
</asp:GridView>
The grid gets displayed OK when not in editing mode - the selected PBX type shows its value in the asp:Label control. No surprise there.
I load the list of values for the DropDownList into a local member called _pbxTypes in the OnLoad event of the form. I verified this - it works, the values are there.
Now my challenge is: when the grid goes into editing mode for a particular row, I need to bind the list of PBX's stored in _pbxTypes.
Simple enough, I thought - just grab the drop down list object in the RowEditing event and attach the list:
protected void grvSecondaryLocations_RowEditing(object sender, GridViewEditEventArgs e)
{
grvSecondaryLocations.EditIndex = e.NewEditIndex;
GridViewRow editingRow = grvSecondaryLocations.Rows[e.NewEditIndex];
DropDownList ddlPbx = (editingRow.FindControl("ddlPBXTypeNS") as DropDownList);
if (ddlPbx != null)
{
ddlPbx.DataSource = _pbxTypes;
ddlPbx.DataBind();
}
.... (more stuff)
}
Trouble is - I never get anything back from the FindControl call - seems like the ddlPBXTypeNS doesn't exist (or can't be found).
What am I missing?? Must be something really stupid.... but so far, all my Googling, reading up on GridView controls, and asking buddies hasn't helped.
Who can spot the missing link? ;-)
Quite easy... You're doing it wrong, because by that event the control is not there:
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow &&
(e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
{
// Here you will get the Control you need like:
DropDownList dl = (DropDownList)e.Row.FindControl("ddlPBXTypeNS");
}
}
That is, it will only be valid for a DataRow (the actually row with data), and if it's in Edit mode... because you only edit one row at a time. The e.Row.FindControl("ddlPBXTypeNS") will only find the control that you want.
I am using a ListView instead of a GridView in 3.5. When the user wants to edit I have set the selected item of the dropdown to the exising value of that column for the record. I am able to access the dropdown in the ItemDataBound event. Here's the code:
protected void listViewABC_ItemDataBound(object sender, ListViewItemEventArgs e)
{
// This stmt is used to execute the code only in case of edit
if (((ListView)(sender)).EditIndex != -1 && ((ListViewDataItem)(e.Item)).DisplayIndex == ((ListView)(sender)).EditIndex)
{
((DropDownList)(e.Item.FindControl("ddlXType"))).SelectedValue = ((MyClass)((ListViewDataItem)e.Item).DataItem).XTypeId.ToString();
((DropDownList)(e.Item.FindControl("ddlIType"))).SelectedValue = ((MyClass)((ListViewDataItem)e.Item).DataItem).ITypeId.ToString();
}
}
protected void grvSecondaryLocations_RowEditing(object sender, GridViewEditEventArgs e)
{
grvSecondaryLocations.EditIndex = e.NewEditIndex;
DropDownList ddlPbx = (DropDownList)(grvSecondaryLocations.Rows[grvSecondaryLocations.EditIndex].FindControl("ddlPBXTypeNS"));
if (ddlPbx != null)
{
ddlPbx.DataSource = _pbxTypes;
ddlPbx.DataBind();
}
.... (more stuff)
}
You can use SelectedValue:
<EditItemTemplate>
<asp:DropDownList ID="ddlPBXTypeNS"
runat="server"
Width="200px"
DataSourceID="YDS"
DataTextField="CaptionValue"
DataValueField="OID"
SelectedValue='<%# Bind("YourForeignKey") %>' />
<asp:YourDataSource ID="YDS" ...../>
</EditItemTemplate>
The checked answer from balexandre works great. But, it will create a problem if adapted to some other situations.
I used it to change the value of two label controls - lblEditModifiedBy and lblEditModifiedOn - when I was editing a row, so that the correct ModifiedBy and ModifiedOn would be saved to the db on 'Update'.
When I clicked the 'Update' button, in the RowUpdating event it showed the new values I entered in the OldValues list. I needed the true "old values" as Original_ values when updating the database. (There's an ObjectDataSource attached to the GridView.)
The fix to this is using balexandre's code, but in a modified form in the gv_DataBound event:
protected void gv_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow gvr in gv.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow && (gvr.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
{
// Here you will get the Control you need like:
((Label)gvr.FindControl("lblEditModifiedBy")).Text = Page.User.Identity.Name;
((Label)gvr.FindControl("lblEditModifiedOn")).Text = DateTime.Now.ToString();
}
}
}
<asp:GridView ID="GridView1" runat="server" PageSize="2" AutoGenerateColumns="false"
AllowPaging="true" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<Columns>
<asp:TemplateField HeaderText="SerialNo">
<ItemTemplate>
<%# Container .DataItemIndex+1 %>. 
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RollNo">
<ItemTemplate>
<%--<asp:Label ID="lblrollno" runat="server" Text='<%#Eval ("RollNo")%>'></asp:Label>--%>
<asp:TextBox ID="txtrollno" runat="server" Text='<%#Eval ("RollNo")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SName">
<ItemTemplate>
<%--<asp:Label ID="lblsname" runat="server" Text='<%#Eval("SName")%>'></asp:Label>--%>
<asp:TextBox ID="txtsname" runat="server" Text='<%#Eval("SName")%>'> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="C">
<ItemTemplate>
<%-- <asp:Label ID="lblc" runat="server" Text='<%#Eval ("C") %>'></asp:Label>--%>
<asp:TextBox ID="txtc" runat="server" Text='<%#Eval ("C") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cpp">
<ItemTemplate>
<%-- <asp:Label ID="lblcpp" runat="server" Text='<%#Eval ("Cpp")%>'></asp:Label>--%>
<asp:TextBox ID="txtcpp" runat="server" Text='<%#Eval ("Cpp")%>'> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Java">
<ItemTemplate>
<%-- <asp:Label ID="lbljava" runat="server" Text='<%#Eval ("Java")%>'> </asp:Label>--%>
<asp:TextBox ID="txtjava" runat="server" Text='<%#Eval ("Java")%>'> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="lnkbtnUpdate" runat="server" CausesValidation="true" Text="Update"
CommandName="Update"></asp:LinkButton>
<asp:LinkButton ID="lnkbtnCancel" runat="server" CausesValidation="false" Text="Cancel"
CommandName="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" runat="server" CausesValidation="false" CommandName="Edit"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />
<asp:CommandField HeaderText="Select" ShowSelectButton="True" ShowHeader="True" />
</Columns>
</asp:GridView>
<table>
<tr>
<td>
<asp:Label ID="lblrollno" runat="server" Text="RollNo"></asp:Label>
<asp:TextBox ID="txtrollno" runat="server"></asp:TextBox>
</td>
<td>
<asp:Label ID="lblsname" runat="server" Text="SName"></asp:Label>
<asp:TextBox ID="txtsname" runat="server"></asp:TextBox>
</td>
<td>
<asp:Label ID="lblc" runat="server" Text="C"></asp:Label>
<asp:TextBox ID="txtc" runat="server"></asp:TextBox>
</td>
<td>
<asp:Label ID="lblcpp" runat="server" Text="Cpp"></asp:Label>
<asp:TextBox ID="txtcpp" runat="server"></asp:TextBox>
</td>
<td>
<asp:Label ID="lbljava" runat="server" Text="Java"></asp:Label>
<asp:TextBox ID="txtjava" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Submit" runat="server" Text="Submit" OnClick="Submit_Click" />
<asp:Button ID="Reset" runat="server" Text="Reset" OnClick="Reset_Click" />
</td>
</tr>
</table>