Hi i just want to show data in my gridview after selecting value from dropdown list and after selecting my dropdown list when i press on search button data can be seen in gridview. My gridview is connected with my database how can i do that my code is this:
aspx page:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Portal" HeaderText="Portal"
SortExpression="Portal" />
<asp:BoundField DataField="TID" HeaderText="TID" SortExpression="TID" />
<asp:BoundField DataField="PNR" HeaderText="PNR" SortExpression="PNR" />
<asp:BoundField DataField="TicketNumber" HeaderText="TicketNumber"
SortExpression="TicketNumber" />
<asp:BoundField DataField="ESACCode" HeaderText="ESACCode"
SortExpression="ESACCode" />
<asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode"
SortExpression="WaiverCode" />
<asp:BoundField DataField="Remarks" HeaderText="Remarks"
SortExpression="Remarks" />
<asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount"
SortExpression="UnusedTicketAmount" />
<asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount"
SortExpression="ddlUnusedAmount" />
<asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality"
SortExpression="AirlinePenality" />
<asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality"
SortExpression="ddlAirlinePenality" />
<asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess"
SortExpression="NetRefundProcess" />
<asp:BoundField DataField="ddlNetRefundProcess"
HeaderText="ddlNetRefundProcess" SortExpression="ddlNetRefundProcess" />
<asp:BoundField DataField="RefundableCommission"
HeaderText="RefundableCommission" SortExpression="RefundableCommission" />
<asp:BoundField DataField="ddlRefundableCommission"
HeaderText="ddlRefundableCommission" SortExpression="ddlRefundableCommission" />
<asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded"
SortExpression="CouponRefunded" />
<asp:BoundField DataField="RefundType" HeaderText="RefundType"
SortExpression="RefundType" />
<asp:BoundField DataField="DateTime" HeaderText="DateTime"
SortExpression="DateTime" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BartConnectionString %>"
SelectCommand="SELECT * FROM [Test]"></asp:SqlDataSource>
code on aspx.cs page
public void GridViewBind()
{
SqlCommand cmd = new SqlCommand("select * from Test where ID=" + DropDownList1.SelectedValue + "", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Test");
GridView1.DataSource = ds.Tables["Test"];
GridView1.DataBind();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
this.GridViewBind();
}
After selecting value from my dropdown list Error : Invalid column name 'TRAVELONG'
Is ID a string? If so, you need inner quotes for the ID field:
SqlCommand cmd = new SqlCommand("select * from Test where ID='" + DropDownList1.SelectedValue + "'", con);
Otherwise, it may be considering the selected value as a column...
Related
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
this is my gridview page.
style="top: 315px; left: 47px; position: absolute; height: 121px; width: 979px"
AllowPaging="True" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px">
<Columns>
<asp:BoundField DataField="DepartureTime" HeaderText="DepartureTime"
SortExpression="DepartureTime" />
<asp:BoundField DataField="Comments" HeaderText="Comments"
SortExpression="Comments" />
<asp:BoundField DataField="Time" HeaderText="Time"
SortExpression="Time" />
<asp:BoundField DataField="Data" HeaderText="Data"
SortExpression="Data" />
<asp:BoundField DataField="Locations" HeaderText="Location"
SortExpression="Location" />
<asp:BoundField DataField="Destination" HeaderText="Destination"
SortExpression="Destination" />
<asp:BoundField DataField="TrackingID" HeaderText="TrackingID"
SortExpression="TrackingID" />
<asp:BoundField DataField="Shipper" HeaderText="Shipper"
SortExpression="Shipper" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="Receiver" HeaderText="Receiver" SortExpression="Receiver" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="Origin" HeaderText="Origin"
SortExpression="Origin" />
<asp:BoundField DataField="ReceiverAddres" HeaderText="ReceiverAddres"
SortExpression="ReceiverAddres" />
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:sqlConStr %>"
SelectCommand="SELECT * FROM [trackingInfo] WHERE ([TrackingID] = #TrackingID)">
<SelectParameters>
<asp:FormParameter FormField="trackingnumber" Name="TrackingID" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
this is my form page.
this work well when i created is using visual studio and sql management studio
but when i hosted it to my windows web hosting and use the database in my control panel which webadmin is admin software there. this gridview stops working and its showing this error message "Not Found
The requested document was not found on this server.
Web Server at mydomin.org.uk "
i have checked my connectionstring at the web.config file that is good there is no problem there.
please help me for i have put in all ideal to this but is not working.
thanks in advance.
kindly manage your connection string in web.config file......
<ConnectionStrings>
<!--Live--><add name="ConnectionString" connectionString="server=64.5.122.60;user id=user123;password=password;database=databaseName;port=9293" providerName="MySql.Data.MySqlClient"/>
<!--Local--><add name="ConnectionString" connectionString="server=localhost;user id=root;password=root;database=databaseName;port=3306" providerName="MySql.Data.MySqlClient"/>
</ConnectionStrings>
Hope it helpss
protected void Page_Load(object sender, EventArgs e)
{
BindGrid();
}
private void BindGrid()
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["sqlConStr"].ConnectionString);
string sql = "Select * from tableName;";
MySqlCommand command = new MySqlCommand(sql,connection);
command.CommandType = CommandType.Text;
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataTable datatable = new DataTable();
adapter.Fill(datatable);
GridView1.DataSource=datatable;
GridView1.DataBind();
}
This will bind your grid manuly... hope this will help you again... thanks
I have a dateTime field that i am showing in GridView. The problem is I just need to Show The date of the system And not the time but it shows both date and time. What appropriate formatting should be applied?
this sets the date in textbox:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBoxdate.Text = DateTime.Today.ToShortDateString();
}
}
Retrieves from table:
public static List<Workassign> GetTable()
{
List<Workassign> listValues = new List<Workassign>();
string connectionString = "server=(local);database=project_zeshan;Integrated Security=SSPI";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("Select * from Assign_Work", con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Workassign ob = new Workassign();
ob.listItem_1 =rdr["listitem_1"].ToString() ;
ob.listItem_2 = rdr["listitem_2"].ToString();
ob.Description = rdr["Description"].ToString();
ob.Date= DateTime.Parse(rdr["Date"].ToString());
ob.Image = rdr["Image"].ToString();
listValues.Add(ob);
}
return listValues;
}
And the gridView.aspx code:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="listitem_1" HeaderText="ListItem1" />
<asp:BoundField DataField="listItem_2" HeaderText="listItem2" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="Date" HeaderText="Date" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height= "50px" Width = "100px" ImageUrl='<%# Bind("Image") %>' />
</ItemTemplate>
</asp:TemplateField>
</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>
</div>
</form>
Try this:
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:MM/dd/yyyy}" />
You can format the DateTime however you like using ToString() with format string created from the choices here: MSDN - Custom Date and Time Format Strings
// For a standard U.S.-style date:
myDateTime.ToString("MM/dd/yyyy")
// For ISO-style:
myDateTime.ToString("yyyy-MM-dd")
And so on.
EDIT
#JohnH correctly pointed out that in the specific context of working with a GridView, you wouldn't use ToString or other methods, but rather provide a DataFormatString attribute. I'll leave my answer for general use cases of formatting a date and the link to the MSDN resource containing the available format strings.
I have a problem that when ever I try to update a record in the database using gridview update event handler and an updatecommand in sqldatascource
I get the following exception
Incorrect syntax near 'int'.
the weird thing is when I reload the page I find that the record was updated successfully but yet I need this exception message not to appear what should I do
update event handler
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
int BusId = Convert.ToInt32(((DataKey)GridView1.DataKeys[e.RowIndex]).Value);
TextBox Capacity =(TextBox) row.Cells[1].Controls[0];
TextBox DriverName =(TextBox) row.Cells[3].Controls[0];
TextBox Phone =(TextBox) row.Cells[4].Controls[0];
SqlDataSource1.UpdateParameters.Add("capaity", Capacity.Text);
SqlDataSource1.UpdateParameters.Add("id", BusId.ToString());
SqlDataSource1.UpdateParameters.Add("driver", DriverName.Text);
SqlDataSource1.UpdateParameters.Add("phone", Phone.Text);
SqlDataSource1.Update();
}
gridview asp.net code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Bus Number" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="326px" Width="1017px" OnRowUpdating="GridView1_RowUpdating">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Bus Number" HeaderText="Bus Number" ReadOnly="True" SortExpression="Bus Number" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity" SortExpression="Capacity" />
<asp:BoundField DataField="NumberOfBooking" HeaderText="NumberOfBooking" SortExpression="NumberOfBooking" ReadOnly="True" />
<asp:BoundField DataField="Driver" HeaderText="Driver" SortExpression="Driver" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" ShowHeader="False" />
<asp:BoundField DataField="Date Added" HeaderText="Date Added" SortExpression="Date Added" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="True" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</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>
the updatecommand
UpdateCommand="UPDATE Buses SET Capacity = #capaity WHERE VechileId = #id ;UPDATE Vechile SET Driver = #driver, Phone = #phone
WHERE VechileId = #id">
My GridViews which are connected to their respective LinqDataSource(LinqDataSourceMale & LinqDataSourceFemale) are
<asp:GridView ID="GridViewMale" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ID" ForeColor="Black" GridLines="Horizontal" PageSize="5" Width="692px" DataSourceID="LinqDataSourceMale">
<Columns>
<asp:ImageField DataImageUrlField="Image" NullImageUrl="images/bullet.png" ReadOnly="True">
</asp:ImageField>
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Education" HeaderText="Education" SortExpression="Education" />
<asp:BoundField DataField="CurrentStatus" HeaderText="CurrentStatus" SortExpression="CurrentStatus" />
<asp:BoundField DataField="Height" HeaderText="Height" SortExpression="Height" />
<asp:BoundField DataField="Complexion" HeaderText="Complexion" SortExpression="Complexion" />
<asp:BoundField DataField="Caste" HeaderText="Caste" SortExpression="Caste" />
<asp:BoundField DataField="Group" HeaderText="Group" SortExpression="Group" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSourceMale" runat="server" ContextTypeName="MB.BerouDataContext" EntityTypeName="" TableName="Males">
</asp:LinqDataSource>
<asp:GridView ID="GridViewFemale" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ID" ForeColor="Black" GridLines="Horizontal" PageSize="5" Width="693px" DataSourceID="LinqDataSourceFemale">
<Columns>
<asp:ImageField DataImageUrlField="Image" >
</asp:ImageField>
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Education" HeaderText="Education" SortExpression="Education" />
<asp:BoundField DataField="CurrentStatus" HeaderText="CurrentStatus" SortExpression="CurrentStatus" />
<asp:BoundField DataField="Height" HeaderText="Height" SortExpression="Height" />
<asp:BoundField DataField="Complexion" HeaderText="Complexion" SortExpression="Complexion" />
<asp:BoundField DataField="Caste" HeaderText="Caste" SortExpression="Caste" />
<asp:BoundField DataField="Group" HeaderText="Group" SortExpression="Group" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Center" Wrap="True" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSourceFemale" runat="server" ContextTypeName="MB.BerouDataContext" EntityTypeName="" TableName="Females">
</asp:LinqDataSource>
My SearchClick event code is:
protected void ButtonSearch_Click(object sender, EventArgs e)
{
using(BerouDataContext Data = new BerouDataContext())
{
if (DropDownListGender.SelectedItem.Text == "Male")
{
int age = Convert.ToInt32(DropDownListAge.Text);
string education = DropDownListEducation.Text.ToString();
string maritalstatus = DropDownListMaritalStatus.Text.ToString();
string caste = DropDownListCaste.Text.ToString();
string city = DropDownListCity.ToString();
var SearchResultBoys = Data.Males.Where(tan =>
(tan.Age == age)
&& (tan.Education.Contains(education))
&& (tan.Group.Contains(maritalstatus))
&& (tan.Caste.Contains(caste)));
GridViewMale.DataSourceID = "";
GridViewMale.DataSource = SearchResultBoys;
GridViewMale.DataBind();
}
else if (DropDownListGender.SelectedItem.Text == "Female")
{
int age = Convert.ToInt32(DropDownListAge.Text);
string education = DropDownListEducation.Text.ToString();
string maritalstatus = DropDownListMaritalStatus.Text.ToString();
//var religion = DropDownListReligion.Text.ToString();
string caste = DropDownListCaste.Text.ToString();
string city = DropDownListCity.ToString();
var SearchResultGirls = Data.Females.Where(tan =>
(tan.Age == age)
&& (tan.Education.Contains(education))
&& (tan.Group.Contains(maritalstatus))
&& (tan.Caste.Contains(caste)));
GridViewFemale.DataSourceID = "";
GridViewFemale.DataSource = SearchResultGirls;
GridViewFemale.DataBind();
}
}
}
Iam unable to display the data in gridview, gridview doesnt apper after searchClickEvent, please Help.
I think you might need to re-initlize your LinqDataSource data source instead of gridview
Take a look at this tutorial and this thread