Hi kelsen1989,
Check this sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnPageIndexChanging="gvCustomers_PageIndexChanging" OnRowCommand="OnRowCommand"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnSelect" CommandArgument='<%# Container.DataItemIndex %>' CommandName="Select"
runat="server" Text="Select Report" />
<asp:Button ID="btnReport" Text="Get Report" runat="server" OnClick="GetReport" />
</ItemTemplate>
<ItemStyle Width="80px" />
</asp:TemplateField>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" />
<asp:BoundField DataField="ContactName" HeaderText="Name" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlCountry" runat="server" AppendDataBoundItems="true" DataTextField="Country"
DataValueField="Country" DataSourceID="SqlDataSource2">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT [CustomerID], [ContactName], [City], [Country] FROM [Customers]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT DISTINCT [Country] FROM [Customers] WHERE [Country] !=''">
</asp:SqlDataSource>
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Code
C#
protected void GetReport(object sender, EventArgs e)
{
GridViewRow row = ((sender as Button).NamingContainer as GridViewRow);
int index = ((sender as Button).NamingContainer as GridViewRow).RowIndex;
gvCustomers.AllowPaging = false;
gvCustomers.DataBind();
DropDownList ddlcountry = (row.FindControl("ddlCountry") as DropDownList);
string country = ddlcountry.SelectedValue;
Response.Redirect("Report.aspx?country=" + country);
}
protected void gvCustomers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.gvCustomers.PageIndex = e.NewPageIndex;
}
private void BindCustomers()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT CustomerID,ContactName,City,Country FROM Customers", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
this.gvCustomers.DataSource = dt;
this.gvCustomers.DataBind();
}
}
}
}
VB.Net
Protected Sub GetReport(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = (TryCast((TryCast(sender, Button)).NamingContainer, GridViewRow))
Dim index As Integer = (TryCast((TryCast(sender, Button)).NamingContainer, GridViewRow)).RowIndex
gvCustomers.AllowPaging = False
gvCustomers.DataBind()
Dim ddlcountry As DropDownList = (TryCast(row.FindControl("ddlCountry"), DropDownList))
Dim country As String = ddlcountry.SelectedValue
Response.Redirect("Report.aspx?country=" & country)
End Sub
Protected Sub gvCustomers_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
Me.gvCustomers.PageIndex = e.NewPageIndex
End Sub
Private Sub BindCustomers()
Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Using cmd As SqlCommand = New SqlCommand("SELECT CustomerID,ContactName,City,Country FROM Customers", con)
cmd.CommandType = CommandType.Text
Using sda As SqlDataAdapter = New SqlDataAdapter()
sda.SelectCommand = cmd
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
Me.gvCustomers.DataSource = dt
Me.gvCustomers.DataBind()
End Using
End Using
End Using
End Sub
Screenshot