Dear all genius please help me with this had been trying everywhere but no luck. I am trying to open my nested gridview for a single Parent Row but gets open the entire parent row with one single record of the child row. It should be when I click the button of the Parent gridview row then the record for the particular row should display in the Child gridview in the same Parent row, but in my case the record of the Parent row shows up and the Child gridview gets open in all the parent row. Please need in help :(
enter image description here
<asp:GridView runat="server" ID="GridView4" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="UId" class="" CellPadding="4" PageSize="5">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="File Type" Visible="false">
<ItemTemplate>
<asp:Label ID="lblFileType" runat="server" Text='<%# Eval("FileType") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Image Name" Visible="false">
<ItemTemplate>
<asp:Label ID="lblImageName" runat="server" Text='<%# Eval("ImageName") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:ImageButton ID="Image2" class="img1" runat="server" ImageUrl='<%# Bind("pic") %>' OnCommand="blah_Command" CommandName='<%# Eval("UId") %>' CommandArgument='<%# Eval("pic") %>' />
<asp:Panel ID="pnlOrders" runat="server" Style="position: relative" Visible="false">
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="FileSize" HeaderText="Order Id" />
<asp:BoundField ItemStyle-Width="150px" DataField="ShareByUserId" HeaderText="Date" />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#ffffff" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#ffffff" Font-Bold="True" ForeColor="White" />
</asp:GridView>
Code Behind:
protected void blah_Command(object sender, CommandEventArgs e)
{
foreach (GridViewRow row2 in GridView4.Rows)
{
row2.FindControl("pnlOrders").Visible = true;
string customerId = e.CommandName.ToString();
GridView gvOrders = row2.FindControl("gvOrders") as GridView;
BindOrders(customerId, gvOrders);
}
}
private void BindOrders(string customerId, GridView gvOrders)
{
gvOrders.ToolTip = customerId;
gvOrders.DataSource = GetData(string.Format("select * from SShare where UId='{0}'", customerId));
gvOrders.DataBind();
}
You are looping all the rows in GridView4, so every nested GridView will be filled with data.
What you need is the row number of the row that the clicked LinkButton is in, and use that to find the nested GridView.
protected void blah_Command(object sender, CommandEventArgs e)
{
//get the current datagrid item from the sender
GridViewRow row = (GridViewRow)(((Control)sender).NamingContainer);
//the row index of the gridviewrow
int rowIndex = row.RowIndex;
//find the correct nested grid using the row index
GridView gvOrders = GridView4.Rows[rowIndex].FindControl("gvOrders") as GridView;
}
Related
I have a GridView where one column is a checkbox, like this
<ecc:ExportableGridView ID="dgTrxAvailable" runat="server" AutoGenerateColumns="False"
CellPadding="0" FixedColumns="" OnRowDataBound="dgTrxAvailable_OnRowDataBound"
PageIndex="1" Width="100%">
<Columns>
<asp:TemplateField HeaderText="N°" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblCounter" runat="server" ReadOnly="True" CssClass="txtGrid t3 c3"
Text='<%# Container.DataItemIndex + 1 %>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="3%" CssClass="t3" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="TrX" Visible="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="txt_id_transaccion" runat="server" ReadOnly="True" CssClass="txtGrid t3 c3"
Text='<%# Bind("id_transaccion") %>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="10%" CssClass="t3" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Include">
<HeaderTemplate>
<asp:Label ID="Label2" runat="server" Text="Incluir" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="RuleDate" runat="server" Checked='<%#Eval("RuleDate") %>'/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="3%" CssClass="t3" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</ecc:ExportableGridView>
I want to know, of a group of n rows, which checkboxes changed, doesnt't matter if they were unchecked/checked.
What I tried is to add a class to the checkbox like this:
$('input[type=checkbox]').change(function () {
$(this).addClass("Selected");
});
And ask in the backend:
protected void btnApply_Click(object sender, EventArgs e)
{
foreach (GridViewRow item in dgTrxAvailable.Rows)
{
if ((item.FindControl("RuleDate") as CheckBox).CssClass == "Selected")
{
//Logic here
}
}
}
but the value of CssClass is empty and I think there is a better solution to this without using magic strings, etc.
Any ideas?.
How to get the row index of a dynamically created asp.net GridView so that I can edit the record in a text box outside the GridView.
How to get the row index of a dynamically created asp.net GridView so that I can edit the record in a text box outside the GridView.
This is the GridView:
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="RefID">
<ItemTemplate>
<asp:Label ID="lbl_Refid" runat="server" Text='<%# Eval("Refid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbl_date" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name Of Company">
<ItemTemplate>
<asp:Label ID="lbl_noc" runat="server" Text='<%# Eval("Name_Of_Company") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact/Email">
<ItemTemplate>
<asp:Label ID="lbl_wht_do" runat="server" Text='<%# Eval("Contact") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:Label ID="lbl_wht_do" runat="server" Text='<%# Eval("Remarks") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="btn_edit" runat="server" `enter code here` Text="Button" />
</ItemTemplate>
</asp:TemplateField>
</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:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowCommand = "OnRowCommand">
Use
OnRowCommand = "OnRowCommand"
Now when any action happen on the grid the OnRowCommand event is executed.
protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = GridView1.Rows[index];
}
More Info
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="MyButtonClick" />
</ItemTemplate>
and your method
protected void MyButtonClick(object sender, System.EventArgs e)
{
//Get the button that raised the event
Button btn = (Button)sender;
//Get the row that contains this button
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
}
I have a GridView with checkbox, dropdown and button as templatefields.
On button click I have to update the entire row in the data base.
This is my aspx:
<asp:GridView runat="server" ID="Gdv" AutoGenerateColumns="False" Font-Size="Small" CssClass="grid" BackColor="White" BorderWidth="0px" CellPadding="4" Width="100%" AllowSorting="True" SkinID="GVSalesManager" GridLines="none" AllowPaging="true" PageSize="10" PagerStyle-ForeColor="#0066cc" PagerStyle-CssClass="gvPagerCss" PagerStyle-Font-Underline="true" PagerStyle-Wrap="true"
OnPageIndexChanging="GdvCPRetailerMap_PageIndexChanging" OnRowDataBound="GdvCPRetailerMap_RowDataBound">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="S.No" DataField="S.No." SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="2%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="2%"/>
</asp:BoundField>
<asp:TemplateField ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" OnCheckedChanged="chkRow_CheckedChanged" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ReadOnly="true" HeaderText="Customer Id" ItemStyle-HorizontalAlign="Center" DataField="CustomerID" SortExpression="CustomerID">
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="10%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Firm's Name" ItemStyle-HorizontalAlign="Center" DataField="Firm's Name" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="20%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="20%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Retailer Name" ItemStyle-HorizontalAlign="Center" DataField="Retialer Name" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="20%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="20%"/>
</asp:BoundField>
<asp:BoundField ReadOnly="true" HeaderText="Pesticide Licence No." ItemStyle-HorizontalAlign="Center" DataField="Pesticide Licence No" SortExpression="SNo">
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" Width="10%"/>
</asp:BoundField>
<asp:TemplateField HeaderText="Channel Partner-1" HeaderStyle-Font-Bold="true" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlCP1" Enabled="false" ToolTip="Please Click on the checkbox to change the prefered CP" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCP1_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Channel Partner-2" HeaderStyle-Font-Bold="true" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlCP2" Enabled="false" ToolTip="Please Click on the checkbox to change the prefered CP" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCP2_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button runat="server" ID="BtnUpdateRow" Text="Update" ToolTip="Update This Record?" OnClick="BtnUpdateRow_Click" BackColor="#336699" ForeColor="#ffffff"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This is the updatebutton event
protected void BtnUpdateRow_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow grow = (GridViewRow)btn.NamingContainer;
//btn.
CheckBox chkbx = (CheckBox)grow.FindControl("chkRow");
if (chkbx.Checked != true)
{
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Red;
labelErrormessage.Text = "Please Check/Uncheck the CheckBox and Click Update";
return;
}
else
{
/*--Code to update the row's record in the edatabase.--*/
??
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Green;
labelErrormessage.Text = "Updated Succesfully";
return;
}
}
How do I read the row in which the button has been clicked and update its dropdownlist selected values in the database?
If you have some sort of identification data displayed in the gridview you could get the value from the row's cell like this grow.Cells[0].Text then find the record in the database and update its values.
You could also hide the id for example if this is information you dont want to show to the user. The row will still be located at index 0 but hidden.
Sample:
else
{
var record = queryDatabase(grow.Cells[0].Text);
//update record values
updateRecord(record);
labelErrormessage.Visible = true;
labelErrormessage.ForeColor = System.Drawing.Color.Green;
labelErrormessage.Text = "Updated Succesfully";
return;
}
everyone. I needed your help. I am creating an online workshop registration system. I have a inicale gridview that show the all the available workshop for registration during the festival time. I am using a session and check box to get the workshop that the person want into the "shopping cart" on the next page. what I needed to do is after righting a incial order written to an order table in my SQL database. What I am having issues with is when it write the registration data that is stored in an other gridview for the shopping cart. I am writing each row as a new entry into a order detail table. when I do this the program does something very odd. It seem to write all the data from the a gridview that holds all the workshop information on the first page.
code for writing the shopping cart row to the order detail table:
protected void btn_Submit_Click1(object sender, EventArgs e)
{
foreach (GridViewRow row in Basket.Rows)
{
Label lblCatCode = (Label)row.FindControl("lblCatCode");
Label lblTitle = (Label)row.FindControl("lblTitle");
SqlConnection conBasket = new SqlConnection("Data Source=JONS\\SQLEXPRESS;Initial Catalog=OFFFV2;Integrated Security=True");
SqlCommand cmdBasket = new SqlCommand("Insert into OrderDetail(OrderID,CatalogeCode,Title)Values(#OrderID,#CatCode,#Title)", conBasket);
cmdBasket.Parameters.AddWithValue("#OrderID", lblOrderNumber.Text);
cmdBasket.Parameters.AddWithValue("#CatCode", lblCatCode.Text);
cmdBasket.Parameters.AddWithValue("#Title", lblTitle.Text);
try
{
conBasket.Open();
cmdBasket.ExecuteNonQuery();
conBasket.Close();
}
catch (Exception ex)
{
lbl_Error.Text = "A database error has orrued. <br <br />" + "Message: " + ex.Message;
}
}
}
Here is the code for the gridview
<asp:GridView ID="Basket" runat="server" AutoGenerateColumns="False" DataKeyNames="WorkshopID" DataSourceID="BasketData" EnableViewState="False" ShowFooter="True" OnRowCreated="Basket_RowCreate" CellPadding="4" ForeColor="#333333" GridLines="None" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Remove">
<ItemTemplate>
<asp:CheckBox ID="cb_BasketRemove" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cataloge Code" SortExpression="CatalogeCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("CatalogeCode") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCatCode" runat="server" Text='<%# Eval("CatalogeCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<ItemTemplate>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<strong>
Total Price:
</strong>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price" SortExpression="Price">
<ItemTemplate>
<asp:Label ID="Price" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<strong>
<asp:Literal ID="TotalPrice" runat ="server" />
</strong>
</FooterTemplate>
</asp:TemplateField>
</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>
I understand that my last post was unclear and was closed. I am at a loss as why the program is doing what it is doing. I am wondering if it is in connection with the way I get the data from the first gridview to the shopping cart.
Here is the code for the session for the selected row
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btt_Select_Click(object sender, EventArgs e)
{
var selectedWorkshop = GridView1.Rows.Cast<GridViewRow>().Where(row => ((CheckBox)row.FindControl("RegisteredWorkshop")).Checked).Select(row => GridView1.DataKeys[row.RowIndex].Value.ToString()).ToList();
if (Session["cart"] == null)
{
Session["cart"] = selectedWorkshop;
}
else
{
var cart = (List<string>)Session["cart"];
foreach (var workshop in selectedWorkshop)
cart.Add(workshop);
Session["cart"] = cart;
}
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("RegisteredWorkshop");
if (cb.Checked)
cb.Checked = false;
}
}
protected void btt_CheckOut_Click(object sender, EventArgs e)
{
if (Session["cart"] != null)
Response.Redirect("Checkout.aspx");
}
}
The code for the select gridview from where the registrant select from the various workshops:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" CellPadding="4" DataKeyNames="WorkshopID" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText ="Register">
<ItemTemplate>
<asp:CheckBox ID="RegisteredWorkshop" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FestivalYear" HeaderText="Festival Year" />
<asp:BoundField DataField="CatalogeCode" HeaderText="Catalog Code" />
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="WSDescription" HeaderText="Workshop Description" />
<asp:BoundField DataField="DayOffered" HeaderText="Day Offered" />
<asp:BoundField DataField="Lenght" HeaderText="Workshop Lenght" />
<asp:BoundField DataField="BeginingTime" HeaderText="Start Time" />
<asp:BoundField DataField="Price" HeaderText="Workshop Fee" />
<asp:BoundField DataField="WorkshopID" HeaderText="Workshop Id" Visible="False" />
</Columns>
I may be wrong but it looks like your variable naming is off (confusing basket and cart?).
You might need to do something like this:
protected void btn_Submit_Click1(object sender, EventArgs e)
{
var Basket = (List<string>)Session["cart"]; // ADD THIS LINE
foreach (GridViewRow row in Basket.Rows)
{
I have a GridView that has data bounded rows. I'm trying to get specific cell value on the SelectedIndexChanged event of DropDownList. My tries are as follows:
string temp= GridView2.SelectedRow.Cells[3].Text;
string temp = ((DataBoundLiteralControl)GridView2.Rows[0].Cells[3].Controls[0]).Text;
DataBoundLiteralControl dblc = (DataBoundLiteralControl)GridView2.Rows[0].Cells[3].Controls[0];
string temp=dblc.Text;
These all 3 of them returns null.
Moreover, the Control[0] is returning correct value of TemplateFields only, but not DataBound fields.
.aspx
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor=" #d54d7b" HeaderStyle-ForeColor="White"
RowStyle-BackColor="#FFFAFC" AlternatingRowStyle-BackColor="#FFFFF7" AlternatingRowStyle-ForeColor="#000"
AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging" Width="900px" Font-Names="Segoe UI Light" BorderColor="#DEDEDE">
<RowStyle HorizontalAlign="center" />
<Columns>
<asp:BoundField DataField="Description" HeaderText="Description" ItemStyle-Width="80" />
<asp:BoundField DataField="Vacancies" HeaderText="Vacancies" ItemStyle-Width="150" />
<asp:TemplateField HeaderText="Detail">
<ItemTemplate>
<asp:BoundField DataField="Date" HeaderText="Date" ItemStyle-Width="80" />
<asp:BoundField DataField="Time" HeaderText="Time" ItemStyle-Width="80" />
</Columns>
Problem you are probably facing is that, GridView1 hasn't been bounded yet.. that is the reason why Control[0] is returning correct value of TemplateFields but cells in the gridview returns null.
You can do the following
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
/// send value to filter or bind gridView1
/// bind gridvew
string temp = GridView1.Rows[0].Cells[3].Text;
/// or any code to get values from GridView Cell
}
I Converted all <asp:BoundFields> to <asp:TemplateField> and it looked like this:
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor=" #009C0D" HeaderStyle-ForeColor="White"
RowStyle-BackColor="#FFFAFC" AlternatingRowStyle-BackColor="#FFFFF7" AlternatingRowStyle-ForeColor="#000"
AutoGenerateColumns="false" AllowPaging="true" CssClass="test"
HtmlEncode="true"
Font-Names="Segoe UI Light" BorderColor="#DEDEDE" >
<RowStyle HorizontalAlign="center" />
<Columns>
<asp:TemplateField HeaderText="Description" ControlStyle-Width="250px" ><ItemTemplate> <asp:LinkButton ID= "Description" PostBackUrl='<%# Eval("Description", "~/{0}.aspx") %>' Text='<%# Eval("Description")%>' runat="server" ></asp:LinkButton> </ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Vacancies"><ItemTemplate> <asp:Label ID="Vacancies" Text='<%# Eval("Vacancies")%>' runat="server" ></asp:Label> </ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Detail"><ItemTemplate><asp:Label ID="City" Text='<%# Eval("City")%>' runat="server" ></asp:Label> <div style="font-size:10px"> <asp:Label ID="Label1" Text='<%# Eval("DateDay")%>' runat="server" ></asp:Label> </div> </ItemTemplate></asp:TemplateField>
//and others
</Columns>
</asp:GridView>
And get specific value by entering this code behind DropDownList:
if (dropdown.SelectedIndex != -1)
{
ListItem mySelectedItem = (from ListItem li in dropdown.Items where li.Selected == true select li).First();
foreach (GridViewRow rw in GridView2.Rows)
{
Label tv = (Label)rw.Cells[3].FindControl("City");
if (tv.Text.IndexOf(mySelectedItem.Text) != -1)
{
rw.Visible = true;
}
else
rw.Visible = false;
}
}