In my first load of my aspx page, I have a GridView that are filled.
In my ASPX page I handle the click event on my radio button
$("#ctl00_contentConteudo_rbBuscas_1").click(function () {
$.get("../Gerenciar/ListaUsuarioProvisorio.aspx?Documentacao=s&r=" + Math.random(2), {}, function (data) {
});
});
So, this force to pass in my page load again when my radio button is clicked.
ASPX
<div id="infoGrid" runat="server">
<cc1:GridView ID="grdImoveis" CssClass="StyleGrid" Width="100%" runat="server" ShowHeader="false"
AutoGenerateColumns="False" DataSourceID="dsGrid" BorderWidth="0px" GridLines="None"
AllowPaging="True" EnableModelValidation="True" >
<AlternatingRowStyle BackColor="White" CssClass="EstiloDalinhaAlternativaGrid" HorizontalAlign="Center" />
<RowStyle CssClass="EstiloDalinhaGrid" HorizontalAlign="Center" />
<Columns>
<asp:BoundField HeaderText="Nome" DataField="NomeCompleto" />
<asp:BoundField HeaderText="Cargo" DataField="DescricaoCargo1" />
<asp:BoundField HeaderText="Data Cadastro" DataField="DataHora" />
<asp:TemplateField ControlStyle-CssClass="acoes_lista_imovel" HeaderText="Curso">
<ItemTemplate>
<div class="acoes_lista_imovel">
<%# montaIcones(Eval("Usuario_Id").ToString())%>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</cc1:GridView>
<asp:SqlDataSource ID="dsGrid" runat="server"></asp:SqlDataSource>
</div>
CODE BEHIND
In my code behind, my PageLoad just call my CarregaLista method, that fill my GridView
protected void CarregaLista()
{
string documentacao = Request.QueryString["Documentacao"].ToString();
if (documentacao.Equals("s"))
{
string select = string.Empty;
select += "SELECT top 10 San_Credenciada.Apelido, San_Usuario.NomeCompleto, San_Usuario.Usuario_Id, San_Usuario.DescricaoCargo1, "
+ "CONVERT(varchar, San_Usuario.DataHora, 103) AS DataHora "
+ "FROM San_Usuario "
+ "JOIN San_Credenciada "
+ "ON San_Usuario.Credenciada_Id = San_Credenciada.Credenciada_Id "
+ "WHERE San_Usuario.Excluido = 0 "
+ "GROUP BY San_Credenciada.Apelido, San_Usuario.NomeCompleto, San_Usuario.Usuario_Id, "
+ "San_Usuario.DescricaoCargo1, San_Usuario.DataHora "
+ "ORDER BY San_Usuario.DataHora ASC ";
dsGrid.ConnectionString = c.Con;
dsGrid.SelectCommand = select;
dsGrid.DataBind();
grdImoveis.DataBind();
dsGrid.Dispose();
}
}
}
WITH UPDATE PANEL
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:RadioButton ID="RadioButton2" runat="server" Text="Curso Básico Netimóveis" />
<asp:RadioButton ID="RadioButton1" runat="server" Text="Buscar Lista de Presença" />
<asp:RadioButton ID="rdBuscas" runat="server" OnCheckedChanged="Click" Text="Curso Documentação Imobiliária" />
<cc1:GridView ID="grdImoveis" CssClass="StyleGrid" Width="100%" runat="server" ShowHeader="false"
AutoGenerateColumns="False" DataSourceID="dsGrid" BorderWidth="0px" GridLines="None"
AllowPaging="True" EnableModelValidation="True" >
<AlternatingRowStyle BackColor="White" CssClass="EstiloDalinhaAlternativaGrid" HorizontalAlign="Center" />
<RowStyle CssClass="EstiloDalinhaGrid" HorizontalAlign="Center" />
<Columns>
<asp:BoundField HeaderText="Nome" DataField="NomeCompleto" />
<asp:BoundField HeaderText="Cargo" DataField="DescricaoCargo1" />
<asp:BoundField HeaderText="Data Cadastro" DataField="DataHora" />
<asp:TemplateField ControlStyle-CssClass="acoes_lista_imovel" HeaderText="Curso">
<ItemTemplate>
<div class="acoes_lista_imovel">
<%# montaIcones(Eval("Usuario_Id").ToString())%>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</cc1:GridView>
<asp:SqlDataSource ID="dsGrid" runat="server"></asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdBuscas" />
</Triggers>
</asp:UpdatePanel>
My problem is that my GridView don't refresh with this query.
How can I solve this ?
You can use Ajax Tretament - based on UpdatePanel, Triggers and UpdateMode="Condition"
You can use this code (Adjust your GridView and Id of your radio button on trigger)
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ModeUpdate="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server">
<Columns>
......
</Columns>
</asp:GridView>
<asp:RadioButton ...../>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="YourRadioButtonId" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Related
Background: The problem I have with my code is the following. Upon the first click of a button the checkbox doesn't get the checked checkboxes, but on the second click just get all the checked checkboxes.
Here is the code:
ASPX
This button execute the process..
<asp:LinkButton ID="lbDeletePerman" runat="server" OnClick="lbDeletePerman_Click">Yes</asp:LinkButton>
<code><asp:UpdatePanel ID="GVUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView CssClass="da-table" ID="Gv_A" runat="server" DataKeyNames="ID,PatientName" AutoGenerateColumns="false" OnRowCommand="Gv_Appoint_RowCommand">
<Columns>
<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CbE" runat="server" />
<asp:HiddenField ID="hID" Value='<%# Eval("IDENTIFICATION") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField=""Date" HeaderText="Date" HeaderStyle-Font-Bold="true" HeaderStyle-VerticalAlign="Middle" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField DataField="Cat" HeaderText="Type" HeaderStyle-Font-Bold="true" HeaderStyle-VerticalAlign="Middle" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField DataField="Deleted" HeaderText="Deleted" HeaderStyle-Font-Bold="true" HeaderStyle-VerticalAlign="Middle" ItemStyle-VerticalAlign="Middle" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
C#:
protected void lbDeletePerman_Click(object sender, EventArgs e)
{
try
{
foreach (GridViewRow rowItem in Gv_Appoint.Rows)
{
CheckBox CboxElim = (CheckBox)(rowItem.Cells[0].FindControl("CbE"));
if (CboxElim.Checked)
{
LBLT.Text = "Hello"; // NO ENTERING HERE
}
}
GVUpdatePanel.Update();
} catch (Exception er){}
}
Any help would be appreciated
lbDeletePerman needs to be inside UpdatePanel together with Gv_A.
Or use the AsyncPostBackTrigger
<asp:LinkButton ID="lbDeletePerman" runat="server"
OnClick="lbDeletePerman_Click">Yes</asp:LinkButton>
<asp:UpdatePanel ID="GVUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbDeletePerman" />
</Triggers>
<asp:GridView>...</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
I have a GridView control, and inside of this control I have defined a link button using GridView.ItemTemplate.
I am using this to open a new window on click. When I click on the link button, however, the page refreshes before opening the new window.
How can I stop the page from refreshing after the link button is clicked?
HTML
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:GridView ID="DataGrid1" style="visibility:visible" runat="server" AlternatingRowStyle-BackColor="#E9EDF5" Font-Names="Arial"
ForeColor="#09538A" Font-Size="12px" BackColor="#ffffff" BorderColor="DarkGray" Font-Bold="true"
HeaderStyle-BackColor="#298DC7" EnableViewState="false" CellSpacing="20"
CellPadding="10" HeaderStyle-Font-Bold="true" AutoGenerateColumns="False" OnRowCommand="DataGrid1__RowCommand" OnRowDataBound="DataGrid1__RowDataBound" >
<HeaderStyle Font-Names="Arial;" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="White" Font-Bold="True" Height="20" BackColor="#298DC7" ></HeaderStyle>
<asp:templatefield headertext="NDC" ItemStyle-CssClass="col" ItemStyle-HorizontalAlign="Justify" HeaderStyle-Width="10%" ItemStyle-Width="10%"> <Columns>
<itemtemplate>
<asp:linkbutton id="productcode" ForeColor="#09538A" runat="server" text='<%#Eval("product code")%>'></asp:linkbutton>
</itemtemplate>
</asp:templatefield>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" BackgroundCssClass="modalBackground" CancelControlID="cancel" TargetControlID="Button3" runat="server" PopupControlID="pnlpopup"> </AjaxToolkit:ModalPopupExtender>
<asp:Button ID="Button3" runat="server" style="visibility:hidden" Text="Button" />
<asp:Panel ID="pnlpopup" CssClass="PanelPopup" runat="server">
<div style="width:inherit;text-align:center;">Products of <%=ndc %> Product Family</div>
<asp:GridView ID="GridView1" runat="server" AlternatingRowStyle-BackColor="#f1f4f8" Width="980px" Font-Names="Arial"
Font-Bold="True" ForeColor="#09538A" Font-Size="13px" BackColor="#ffffff" BorderColor="DarkGray"
HeaderStyle-BackColor="#99cccc" EnableViewState="false" CellSpacing="0" style="padding:10px;"
CellPadding="3" ShowFooter="false" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="productInfo_RowDataBound" >
<HeaderStyle Height="10%" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="true" BackColor="#298DC7"></HeaderStyle>
<rowstyle Height="20px" />
<alternatingrowstyle Height="20px"/>
<Columns>
<asp:boundfield datafield="product code" sortexpression="customers " ItemStyle-CssClass="col" headertext="NDC"/>
<div id="div<%# Convert.ToString(Eval("customer"))+ Convert.ToString(Eval("ManufacturingPartner"))+ Convert.ToString(Eval("product code"))+ Convert.ToString(Eval("Sales Person")) %>" style="display: none; position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvOrderInfo" runat="server" ForeColor="#09538A" AutoGenerateColumns="false" BorderStyle="Double" BorderColor="#df5015" Width="500px" OnRowDataBound="gvOrderInfo_RowDatabound">
<HeaderStyle CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="True" BackColor="#298DC7"></HeaderStyle>
<RowStyle BackColor="#E1E1E1" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
<Columns>
<asp:BoundField DataField="Order Number" HeaderText="Order Number" ItemStyle-Width="75px" ItemStyle-CssClass="col" HeaderStyle-HorizontalAlign="Left" />
</Columns>
</Columns>
</asp:GridView>
</div>
</asp:GridView>
</asp:Panel>
Codebehind
protected void DataGrid1__RowDataBound(Object sender, GridViewRowEventArgs e)
{
this.UpdatePanel4.Update();
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnk = e.Row.FindControl("ppp") as LinkButton;
lnk.Click += new EventHandler(link_Click);
//ScriptManager.GetCurrent(this).RegisterPostBackControl(lnk);
// string a = String.Format("0:N}",Convert.ToDecimal(e.Row.Cells[3].Text));
if (e.Row.Cells[0].Text != "Total")
{
//M1-Fmodification starts from here
if (ListBox2.Items.Count > 0)
//if (DataGrid1.Columns[0].Visible == true)
{
}
}
}
}
I would not use a LinkButton, but a straight html link.
<ContentTemplate>
<a href="#" ID='<%#Eval("product code")%>' onclick="doSomething();">
<%#Eval("productcode")%>
</a>
</ContentTemplate>
And then you can define some javascript in the page.
function doSomething(ProductCode) {
// enter the code here to open the window
}
Also, I would stay away from using UpdatePanel, but that's just my preference.
I've a grid view with three columns Employee name Employee details and Employee age.
I want to add a check box at each row and after selection of each check box i want to fire a insert query associated to that employee.
Can you tell me how to add this dynamic functionality to the grid view.
also if we use <%# EVAL %> i don't know how to implement it with checkbox.
ASPX:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="details" HeaderText="details"
SortExpression="details" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
</Columns>
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="OK" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:connApps %>"
SelectCommand="SELECT [name], [details], [age] FROM [tblA]">
</asp:SqlDataSource>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
Code behind:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Selected item name:<br>";
foreach (GridViewRow item in GridView1.Rows)
{
CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
if (chk != null)
{
if (chk.Checked)
{
Label1.Text += item.Cells[1].Text + "<br>";
}
}
}
}
Output:
Here is an example ,
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px"
CellPadding="0" CellSpacing="0" DataKeyNames="CategoryID" Font-Size="10"
Font-Names="Arial" GridLines="Vertical" Width="40%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkStatus" runat="server"
AutoPostBack="true" OnCheckedChanged="chkStatus_OnCheckedChanged"
Checked='<%# Convert.ToBoolean(Eval("Approved")) %>'
Text='<%# Eval("Approved").ToString().Equals("True") ? " Approved " : " Not Approved " %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />
</Columns>
<HeaderStyle BackColor="#336699" ForeColor="White" Height="20" />
For more information , check Here !
you can use TemplateFields for the GridView:
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID="myCheckBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and in code behind use below code:
ClusterName = GV.Rows(1).Cells(2).FindControl("myLabelinTheGridViewTemplateField")
I have a gridview with a linkbutton that when you click it a Modal Pop Up appears with detail of the row clicked. This works fine if the gridview is not in a update panel. I have to update the gridview every second. If I used the update panel the Modal Pop Up shows up blank. Any ideas in how to get it to work in an update panel?
<div class="Info">
<asp:UpdatePanel ID="UpdatePanelMain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvMain" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
Width="688px" AllowPaging="True" AutoGenerateColumns="false" OnSelectedIndexChanged="gvMain_SelectedIndexChanged"
Font-Size="14px" PageSize="8" DataKeyNames="TicketId, TicketNumber"
OnRowCommand="gvMain_RowCommand" OnPageIndexChanging="gvMain_PageIndexChanging"
OnRowDataBound="gvMain_RowDataBound">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="TicketId" HeaderText="Id" SortExpression="TicketId"
Visible="false">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="TicketNumber" HeaderText="Ticket #Id" SortExpression="TicketNumber"
Visible="false">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="DisplayNum" HeaderText="Ticket Number" SortExpression="DisplayNum">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbTicketInfo" runat="server" CommandName="Popup" OnClick="lblTicketInfo_Click">LinkButton</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerGVMain" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="TimerGVMain" Interval="1000" runat="server" OnTick="TimerGVMain_Tick">
</asp:Timer>
<%--Used for modal popup--%>
<asp:Button ID="btnTarget" runat="server" Style="display: none;" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnTarget"
PopupControlID="Div1" DropShadow="True" CancelControlID="btnCloseModal" Drag="True">
</asp:ModalPopupExtender>
<div id="Div1" runat="server" style="background-color: #5D7B9D; color: White; border: #284775 3px solid;
width: 300px; height: 150px; font-size: 10pt; font-family: Verdana;">
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<asp:GridView ID="gvTicketInfo" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Desc" HeaderText="Trans Type" SortExpression="Desc" />
<asp:BoundField DataField="Time" HeaderText="Est Trans Time" SortExpression="Time" />
</Columns>
</asp:GridView>
<%--Button used to close Modal Pop up--%>
<asp:Button ID="btnCloseModal" runat="server" Text="Close" />
</div>
aspx.cs
protected void gvMain_RowCommand(object sender, GridViewCommandEventArgs e)
{
RowIndex = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "Popup" && e.CommandArgument != null)
{
string displayNo = gvMain.Rows[RowIndex].Cells[3].Text;
//string displayNo = gvMain.DataKeyNames[RowIndex]["DisplayNum"].ToString();
ModalPopupExtender1.Show();
try
{
using (SqlConnection cs = new SqlConnection(connStr))
{
SqlDataAdapter da = new SqlDataAdapter("spClerkUI_ShowAllTrans_inTicket", cs);
da.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("#Location", qStatic);
da.SelectCommand.Parameters.AddWithValue("#DisplayNum", displayNo);
DataSet ds = new DataSet();
da.Fill(ds);
gvTicketInfo.DataSource = ds;
gvTicketInfo.DataBind();
Label1.Text = string.Format("<Br>Row # {0}", RowIndex);
}
}
catch (Exception ex)
{
lblStatus.Text = "Modal Error: " + ex.ToString();
}
}
}
protected void gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton ImageButtonTicketInfo = (LinkButton)e.Row.FindControl("lbTicketInfo");
ImageButtonTicketInfo.CommandArgument = e.Row.RowIndex.ToString();
}
}
Add this after Page directory
<%# Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
And place ModalPopupExtender1.Show(); in the try block
And add
Div1.Visible = true;
gvTicketInfo.Visible = true;
I thnk the timer needs to be inside the update panel
I need to show a Master/Child data in a page and I have used multiple GridViews to achieve the same. So, I have created two GridViews (Parent & Child) and now I want to fire the Button click event (i.e. btnLock) from the child gridview control and do some DB operations. So, I dont know how to achieve this.
Please help.
<asp:UpdatePanel ID="pnlUpdate" runat="server">
<ContentTemplate>
<asp:GridView Width="100%" AllowPaging="True" ID="gvCustomers" AutoGenerateColumns="False"
DataSourceID="sqlDsCustomers" runat="server" ShowHeader="False" OnRowCreated="gvCustomers_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div class="group" id='<%#String.Format("customer{0}",Container.DataItemIndex) %>' onclick='showhide(<%#String.Format("\"#customer{0}\"",Container.DataItemIndex) %>,<%#String.Format("\"#order{0}\"",Container.DataItemIndex) %>)'>
<asp:Image ID="imgCollapsible" CssClass="first" ImageUrl="~/Assets/img/plus.png"
Style="margin-right: 5px;" runat="server" /><span class="header">
<%#Eval("CustomerID")%>
:
<%#Eval("CompanyName")%>
(<%#Eval("TotalOrders")%>
Orders) </span>
</div>
<asp:SqlDataSource ID="sqlDsOrders" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
SelectCommand="SELECT [OrderID], [OrderDate], [RequiredDate], [Freight], [ShippedDate] FROM [Orders] WHERE ([CustomerID] = #CustomerID)">
<SelectParameters>
<asp:Parameter Name="CustomerID" Type="String" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
<div id='<%#String.Format("order{0}",Container.DataItemIndex) %>' class="order">
<asp:GridView AutoGenerateColumns="false" CssClass="grid" ID="gvOrders" DataSourceID="sqlDsOrders"
runat="server" ShowHeader="true" EnableViewState="false">
<RowStyle CssClass="row" />
<AlternatingRowStyle CssClass="altrow" />
<Columns>
<asp:TemplateField ItemStyle-CssClass="rownum">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Order ID" DataField="OrderID" ItemStyle-Width="80px" />
<asp:BoundField HeaderText="Date Ordered" DataField="OrderDate" DataFormatString="{0:MM/dd/yyyy}"
ItemStyle-Width="100px" />
<asp:BoundField HeaderText="Date Required" DataField="RequiredDate" DataFormatString="{0:MM/dd/yyyy}"
ItemStyle-Width="110px" />
<asp:BoundField HeaderText="Freight" DataField="Freight" DataFormatString="{0:c}"
ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Right" />
<asp:BoundField HeaderText="Date Shipped" DataField="ShippedDate" DataFormatString="{0:MM/dd/yyyy}"
ItemStyle-Width="100px" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnLock" Text="Lock" CommandName="Lock" CommandArgument=<%# Eval("OrderID") %> runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Thanks
Use the RowCommand:
<asp:GridView AutoGenerateColumns="false" CssClass="grid" ID="gvOrders" DataSourceID="sqlDsOrders"
runat="server" ShowHeader="true" EnableViewState="false"
onrowcommand="gvOrders_RowCommand"
>
........
</asp:GridView >
protected void gvOrders_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="Lock")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
//dowork
}
}