Specifying columns in gridview just adds more columns - asp.net

I have a gridview where I only want certain columns from the query to show (1 is used for sorting). Below I tried to define the columns but for some reason its rendering the columns and then all of the columns in the query afterwords.
<asp:GridView ID="taskGridView" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Person" HeaderText="Person" SortExpression="Person" />
<asp:BoundField DataField="Effort" HeaderText="Effort" SortExpression="Effort" />
<asp:BoundField DataField="Task" HeaderText="Task" SortExpression="Task" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="OriginalEstimateHours" HeaderText="OriginalEstimateHours" SortExpression="OriginalEstimateHours" />
<asp:BoundField DataField="Total" HeaderText="Total" SortExpression="Total" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
</center>
This is what it looks like:
How do I only show desired columns?

GridView control has a property AutoGenerateColumns, that specifies whether the control should generate columns based on the data source that was given to it. Default value of this property is true (MSDN reference), which means that default behavior is to generate all columns and then append markup-defined ones.
To disable this behavior simply set this property to false:
<asp:GridView ID="taskGridView" runat="server" AutoGenerateColumns="false" ...

Related

Dinamically created checkboxes, event handler and more - vb.NET asp.NET

I'm trying to manage the checkall control in a gridview but I'm facing several problems.
This is my gridview control:
<asp:GridView ID="gvShow" runat="server" AutoPostback="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" Height="224px" HorizontalAlign="Center" Width="761px" CellPadding="4" ForeColor="#333333" DataSourceID="sid_db">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField ItemStyle-Width="50px">
<HeaderTemplate>
<asp:CheckBox ID="chkCheckAll" runat="server" AutoPostBack="False" OnCheckedChanged="chkCheckAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkCheck" runat="server" />
</ItemTemplate>
<ItemStyle Width="50px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="Scope" HeaderText="Scope" SortExpression="Scope" />
<asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
<asp:BoundField DataField="Site ID" HeaderText="Site ID" SortExpression="Site ID" />
<asp:BoundField DataField="Site Name" HeaderText="Site Name" SortExpression="Site Name" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="CAP" HeaderText="CAP" SortExpression="CAP" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:BoundField DataField="Master_ID" HeaderText="Master_ID" SortExpression="Master_ID" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol">
<HeaderStyle CssClass="hiddencol"></HeaderStyle>
<ItemStyle CssClass="hiddencol"></ItemStyle>
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
First problem:
The checkbox controls are dynamically created and I honestly have the feeling that I should create an event handler for those, but I don't know how to do it nor I know where to put/write that code. I just see those controls are not recognized once I try to reference them in my code.
Second problem:
Since I'm pretty much a newbie, I made a step back and tested with some junk code if I was able to have all the checkboxes dinamically checked at page load... here is my test... the result a complete failure, nothing happens. I even tried to put the code in the init event, but the result is the same.
For Each row As GridViewRow In gvShow.Rows
DirectCast(row.FindControl("chkCheck"), CheckBox).Checked = True
Next
I would be grateful if anyone could help me with these problems.
Thanks in advance for your time.
Regards,
I have found the answer myself. I had to change the code as follow:
<asp:GridView ID="gvShow" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" Height="224px" HorizontalAlign="Center" Width="761px" CellPadding="4" ForeColor="#333333">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField ItemStyle-Width="50px">
<HeaderTemplate>
<asp:CheckBox ID="ChkSelectAll" runat="server" Autopostback="True" OnCheckedChanged="ChkSelectAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="ChkSigleItem" runat="server" OnCheckedChanged="ChkSigleItem_CheckedChanged" />
</ItemTemplate>
<ItemStyle Width="50px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="Scope" HeaderText="Scope" SortExpression="Scope" />
<asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
<asp:BoundField DataField="Site ID" HeaderText="Site ID" SortExpression="Site ID" />
<asp:BoundField DataField="Site Name" HeaderText="Site Name" SortExpression="Site Name" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="CAP" HeaderText="CAP" SortExpression="CAP" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:BoundField DataField="Master_ID" HeaderText="Master_ID" SortExpression="Master_ID" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol">
<HeaderStyle CssClass="hiddencol"></HeaderStyle>
<ItemStyle CssClass="hiddencol"></ItemStyle>
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
And then:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
''Set value for default SQL query
Dim query As String
query = "SELECT Sites.Master_ID AS Master_ID, Scopes.Name AS Scope, Brands.Extension AS [Brand], Sites.ID AS [Site ID], Sites.Name AS [Site Name], Sites.Address, Sites.CAP, Sites.City, Countries.Name AS Country FROM Sites INNER JOIN Scopes ON Sites.scope_ID = Scopes.ID INNER JOIN Brands ON Sites.brand_ID = Brands.ID INNER JOIN Countries ON Sites.country_ID = Countries.ID"
sid_db.SelectCommand = query
gvShow.DataSource = sid_db
gvShow.DataBind()
End If
End Sub
Protected Sub ChkSelectAll_CheckedChanged(sender As Object, e As EventArgs)
Dim a As Boolean = DirectCast(sender, CheckBox).Checked
For Each row As GridViewRow In gvShow.Rows
Dim cbx As CheckBox = row.FindControl("ChkSigleItem")
cbx.Checked = a
Next
End Sub

How to show Gridview Header on Pageload?

Can you please help on how to show the header of gridview when I load the page. Here in my aspx page. Thanks in advance
<asp:GridView ID="grvProductInventory" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" class="table-responsive table table-striped jambo_table bulk_action" CellPadding="4" ForeColor="#333333" GridLines="None">
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowDeleteButton="True" DeleteText="Remove" />
<asp:BoundField HeaderText="Seller" DataField="pSeller"/>
<asp:BoundField HeaderText="Buyer " DataField="pBuyer"/>
<asp:BoundField HeaderText="QTY" DataField="pQTY" DataFormatString="{0:#,###0.000}"/>
<asp:BoundField HeaderText="Code" DataField="pCode" />
<asp:BoundField HeaderText="Product" DataField="pProduct" />
<asp:BoundField HeaderText="Date From" DataField="Date1" DataFormatString ="{0:dd/M/yyyy}" />
<asp:BoundField HeaderText="Date To" DataField="Date2" DataFormatString ="{0:dd/M/yyyy}" />
<asp:BoundField HeaderText="Total Days" DataField="TotalDays" />
<asp:BoundField HeaderText="Pur Prem" DataField="pPurPremium" />
<asp:BoundField HeaderText="Ave" DataField="Ave" DataFormatString="{0:#,###0.000}"/>
<asp:BoundField HeaderText="Net Price" DataField="NetPurPrice" DataFormatString="{0:#,###0.000}"/>
<asp:BoundField HeaderText="USD" DataField="USD" DataFormatString="{0:#,###0.000}"/>
<asp:BoundField HeaderText="AED" DataField="AED" DataFormatString="{0:#,###0.000}"/>
</Columns>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
you can bind gridview with blank dataset or datatable.
Then show only gridview column.
Set the property of grid view ShowHeaderWhenEmpty="true".
And then
bind the empty dataset or datatable to gridview.
GridView1.DataSource = dt;
GridView1.DataBind();

Update control from .NET DataGrid on row select

I have what seems on the surface a really simple requirement. I want to update a label with a value from the data source when a user clicks a field in a datagrid control.
My page has an SqlDataSource control on it, which returns (for example) 6 columns. I display 5 of them in the datagrid, and want the sixth column shown in a label when the user selects a row.
I have tried various things, with limited success. One way I was convinced would work was to include the column in the datagrid, but set it to Visible="false". However, it turns out that if you do this, the value of row(5).text is ""... Not what I expected.
Any quick way of achieving this?
-- EDIT - Added in code samples --
<asp:GridView ID="gridL250Tickets" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Ridge" BorderWidth="2px" Caption="Last 250 Tickets" CellPadding="3" CellSpacing="1" DataKeyNames="TICKETID" DataSourceID="sqlSlxL250Tickets" AllowPaging="True" AllowSorting="True" HorizontalAlign="Center" Width="75%" PageSize="6">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="SUBJECT" HeaderText="Ticket" SortExpression="SUBJECT" />
<asp:BoundField DataField="RECEIVEDDATE" DataFormatString="{0:d}" HeaderText="Received" SortExpression="RECEIVEDDATE" />
<asp:BoundField DataField="COMPLETEDDATE" DataFormatString="{0:d}" HeaderText="Completed" SortExpression="COMPLETEDDATE" />
<asp:BoundField DataField="AREA" HeaderText="Area" SortExpression="AREA" />
<asp:BoundField DataField="CATEGORY" HeaderText="Category" SortExpression="CATEGORY" />
<asp:BoundField DataField="ISSUE" HeaderText="Issue" SortExpression="ISSUE" />
<asp:BoundField DataField="notes1" HeaderText="Notes" SortExpression="notes1" Visible="False" />
<asp:BoundField DataField="USERNAME" HeaderText="Ass. To" SortExpression="USERNAME" />
<asp:BoundField DataField="notes" HeaderText="Notes - l" SortExpression="notes" Visible="false" />
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
VB Code:
Private Sub gridL250Tickets_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gridL250Tickets.SelectedIndexChanged
Dim row As GridViewRow = gridL250Tickets.SelectedRow
Label1.Text = row.Cells(9).Text
End Sub
You could use a hidden <asp:TemplateField> with a label instead. I tested that out and it seems to work.
<asp:GridView ID="gridL250Tickets" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Ridge" BorderWidth="2px" Caption="Last 250 Tickets" CellPadding="3" CellSpacing="1" DataKeyNames="TICKETID" DataSourceID="sqlSlxL250Tickets" AllowPaging="True" AllowSorting="True" HorizontalAlign="Center" Width="75%" PageSize="6">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="SUBJECT" HeaderText="Ticket" SortExpression="SUBJECT" />
<asp:BoundField DataField="RECEIVEDDATE" DataFormatString="{0:d}" HeaderText="Received" SortExpression="RECEIVEDDATE" />
<asp:BoundField DataField="COMPLETEDDATE" DataFormatString="{0:d}" HeaderText="Completed" SortExpression="COMPLETEDDATE" />
<asp:BoundField DataField="AREA" HeaderText="Area" SortExpression="AREA" />
<asp:BoundField DataField="CATEGORY" HeaderText="Category" SortExpression="CATEGORY" />
<asp:BoundField DataField="ISSUE" HeaderText="Issue" SortExpression="ISSUE" />
<asp:BoundField DataField="notes1" HeaderText="Notes" SortExpression="notes1" Visible="False" />
<asp:BoundField DataField="USERNAME" HeaderText="Ass. To" SortExpression="USERNAME" />
<%--<asp:BoundField DataField="notes" HeaderText="Notes - l" SortExpression="notes" Visible="false" />--%>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lblNotes" runat="server" Text='<%# Eval("notes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
//...
Then just find the label in your event and use its text.
Private Sub gridL250Tickets_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gridL250Tickets.SelectedIndexChanged
Dim row As GridViewRow = gridL250Tickets.SelectedRow
Dim lblNotes As Label = row.FindControl("lblNotes")
Label1.Text = lblNotes.Text
End Sub
Instead of setting Visible = "False", try setting the actual CSS of the given column. Display = "none", and switch it back when the grid control is clicked.
Something along the lines of lblNotes.Style.Item("display") = "none". You could also do that in the Javascript if you didn't want to have a pageback.

Open a PDF from a gridview link?

I have a gridview on my webpage with one of the columns as a "Reference Number". The reference number represents the name of a pdf file on the server. Is it possible change this column to a hyperlink column so that when they click on the Reference Number on the row it opens the pdf? For example they click on ReferenceNumber 123456 and it opens up the pdf \server\folder\123456.pdf. Thank you
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ReferenceNumber" HeaderText="Reference #"
SortExpression="ReferenceNumber" />
<asp:BoundField DataField="Teaching_Hospital_Name" HeaderText="Teaching Hospital Name"
SortExpression="Teaching_Hospital_Name" />
<asp:BoundField DataField="Date_of_Payment"
HeaderText="Date" SortExpression="Date_of_Payment" />
<asp:BoundField DataField="Physician_First_Name"
HeaderText="First Name" SortExpression="Physician_First_Name" />
<asp:BoundField DataField="Physician_Last_Name"
HeaderText="Last Name" SortExpression="Physician_Last_Name" />
<asp:BoundField DataField="Recipient_Primary_Business_Street_Address_Line_1"
HeaderText="Address 1"
SortExpression="Recipient_Primary_Business_Street_Address_Line_1" />
<asp:BoundField DataField="Recipient_City" HeaderText="City"
SortExpression="Recipient_City" />
<asp:BoundField DataField="Recipient_State" HeaderText="State"
SortExpression="Recipient_State" />
<asp:BoundField DataField="Recipient_Zip_Code" HeaderText="Zip"
SortExpression="Recipient_Zip_Code" />
<asp:BoundField DataField="Total_Amount_of_Payment" HeaderText="Total_Amount"
SortExpression="Total_Amount_of_Payment" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
You need to change the Reference Number field to a TemplateField instead of a BoundField, this will allow you to put a hyperlink into that field.
Read Using TemplateFields in the GridView Control
From there, I would suggest using an HttpHandler to build the PDF file and stream it to the user. This has two benefits:
There is no postback, so the user does not lose their place in your grid display.
It allows the user to easily view and/or save the PDF separate from you application.

How to make a Gridview template field select the row of data?

I have a command field in a gridview, that as it is, works as it should. When i select it, the row is hilighted. However, i needed to convert this field into a template, so i could give it a ID that i could reference when using a AJAX Mobal control. I did this, and i am able to reference it with my Ajax control just fine, but, now this field does not select the row in the Gridview? The Select value is needed for the Ajax control to pull the data thru. So i think my issue is, How do i use this command field as a template, AND have it select the row? I hope i am explaining my issue correctly.
Here is the snippet of code when i convert it into a template.
Thank you!
<asp:GridView ID="GridView3" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="3" DataKeyNames="Contact_ID" DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None" PageSize="6">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select" Text="Edit"></asp:LinkButton>
<asp:ModalPopupExtender ID="ModalPopupExtender2" runat="server" TargetControlID="LinkButton1" PopupControlID="DetailsView1" BackgroundCssClass="modalBackground"></asp:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Contact_ID" HeaderText="Contact_ID" InsertVisible="False" ReadOnly="True" SortExpression="Contact_ID" Visible="False" />
<asp:BoundField DataField="Contact_Assigned_Username" HeaderText="Username" SortExpression="Contact_Assigned_Username" />
<asp:BoundField DataField="Contact_First_Name" HeaderText="First Name" SortExpression="Contact_First_Name" />
<asp:BoundField DataField="Contact_Last_Name" HeaderText="Last Name" SortExpression="Contact_Last_Name" />
<asp:BoundField DataField="Contact_Email_Address" HeaderText="Email Address" SortExpression="Contact_Email_Address" />
<asp:BoundField DataField="Contact_Cell_Phone" HeaderText="Cell Phone" SortExpression="Contact_Cell_Phone" />
<asp:CheckBoxField DataField="Contact_Administrator" HeaderText="Admin" SortExpression="Contact_Administrator" />
<asp:CheckBoxField DataField="Contact_LineStat_Triggers_Email" HeaderText="Email Triggers" SortExpression="Contact_LineStat_Triggers_Email" />
<asp:CheckBoxField DataField="Contact_LineStat_Triggers_Text" HeaderText="Text Triggers" SortExpression="Contact_LineStat_Triggers_Text" />
<asp:CheckBoxField DataField="Contact_Web_Portal" HeaderText="Web Access" SortExpression="Contact_Web_Portal" />
<asp:BoundField DataField="Contact_Customer_ID" HeaderText="Contact_Customer_ID" SortExpression="Contact_Customer_ID" Visible="False" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
In the RowDataBound event, try something like this:
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButton btn = (LinkButton)e.Row.FindControl("LinkButton1");
btn.OnClientClick = Page.ClientScript.GetPostBackEventReference(GridView3, "Select$" + e.Row.RowIndex.ToString()));
}

Resources