I'm using a gridview to display some data. There is an image button to display a flag. Within the GridView RowDataBound Event i'm changing the visibility of that button. But the visibility didn't get changed. Here is the code:
bool status = true; // getting this via dataset
ImageButton imgTest = (ImageButton)e.Row.FindControl("ImageButton1");
imgTest.Visible = status;
But still visibility is false.
EDIT:
Here is my HTML Code;
<asp:GridView runat="server" ID="gvScheduleView" DataKeyNames="ControlID,IsPrinted, PrintDate, DueDate"
Width="100%" ShowHeader="true" ShowFooter="true" AutoGenerateColumns="false"
OnRowDataBound="gvScheduleView_rowDataBound" Height="100%" CssClass="removePaddingRight">
<Columns>
<asp:TemplateField HeaderText="Type" HeaderStyle-HorizontalAlign="center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%# Eval("Type") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="120">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" Actions" HeaderStyle-HorizontalAlign="Center"
ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div style="text-align: center;">
<table style="margin-left: 28px;">
<tr style="text-align: center;">
<td style="width: 20px">
<asp:ImageButton ID="ibDelete" runat="server" ImageUrl="~/common/images/delete.gif"
OnClick="ibDelete_click" OnClientClick="return confirm('Are you sure you wish to delete this schedule?');"
CommandArgument='<%# Eval("ControlID") %>' ToolTip="Delete Schedule" />
</td>
<td style="width: 20px">
<asp:ImageButton ID="ibRollback" runat="server" ImageUrl="~/common/images/icons/arrow_undo.png"
OnClick="ibRollback_click" CommandArgument='<%# Eval("ControlID") %>' ToolTip="Rollback print generation"
OnClientClick="return confirm('Are you sure you wish to rollback this schedule?');" />
</td>
<td style="width: 20px">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/common/images/icons/email_go.png"
OnClick="ibGenerate_click" CommandArgument='<%# Eval("ControlID") %>' />
<asp:Image ImageUrl="~/common/images/icons/cancel.png" ID="imInfo" runat="server"
Visible="false" ToolTip="DUE DATE IS INVALID - Please change to a future date" />
</td>
<td style="width: 20px">
<asp:ImageButton ID="ibEditProps" runat="server" ImageUrl="~/common/images/icons/building_edit.png"
OnClick="ibEditProps_click" CommandArgument='<%# Eval("ControlID") %>' CommandName='<%# Eval("Type") %>'
ToolTip="Edit Properties" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="DivBtnImgCopy" runat="server" visible = "<% =ShowHideButton() %>">
<asp:ImageButton ID="ibEditProps" runat="server"ImageUrl="~/common/images/icons/building_edit.png"
OnClick="ibEditProps_click"CommandArgument='<%# Eval("ControlID") %>' CommandName='<%# Eval("Type") %>' ToolTip="Edit Properties" />
</div>
Code Behind
protected bool ShowHideButton()
{
bool bStatus = false;
try
{
if (sCondition == "false")
{
bStatus = false;
}
else if (sCondition == "true")
{
bStatus = true;
}
return bStatus;
}
catch { }
}
Related
Here Is the Code, when i try to fire the event in Browser it is not fired
<asp:Panel ID="StateDistrictGrid_pnl" runat="server">
<asp:GridView ID="User_grd" runat="server" DataKeyNames="VoterID" AutoGenerateColumns="False" AllowPaging="True">
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:ImageButton ID="Img_btn" ImageUrl="~/Images/52105-200.png" OnClick="Img_btn_Click" Height="20px" Width="30px" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" Visible="false" />
<asp:BoundField DataField="VoterName" HeaderText="Voter Name" SortExpression="VoterName" />
<asp:BoundField DataField="StateName" HeaderText="State Name" SortExpression="StateName" />
<asp:BoundField DataField="DistrictName" HeaderText="District Name" SortExpression="DistrictName" />
</Columns>
</asp:GridView>
<asp:Label ID="Lbl_Result" runat="server">
<asp:Button ID="BtnShowPopup" runat="server" Text="Edit" />
<asp:ModalPopupExtender ID="Show_mpe" runat="server" TargetControlID="BtnShowPopup" PopupControlID="PopUp_Pnl" CancelControlID="Btn_Cancel" BackgroundCssClass="textbox_radius"></asp:ModalPopupExtender>
<asp:Panel ID="PopUp_Pnl" runat="server" style = "display:none">
<asp:Label Font-Bold = "true" ID = "Details_lbl" runat = "server" Text = "Voter Details" ></asp:Label>
<br />
<table align = "center">
<tr>
<td>
<asp:Label ID = "ID_lbl" runat = "server" Text = "Voter ID" ></asp:Label>
</td>
<td>
<asp:TextBox ID="VoterID_txt" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID = "Voter_lbl" runat = "server" Text = "Voter Name" ></asp:Label>
</td>
<td>
<asp:TextBox ID="VoterName_txt" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID = "Statepnl_lbl" runat = "server" Text = "State Name" ></asp:Label>
</td>
<td>
<asp:TextBox ID="State_txt" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID = "Districtpnl_lbl" runat = "server" Text = "District Name" ></asp:Label>
</td>
<td>
<asp:TextBox ID="District_txt" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" />
</td>
<td>
<asp:Button ID="Btn_Cancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</asp:Label>
</asp:Panel>
and the backend code is like this:
is thier any problem in In my Code please help thank you
protected void Img_btn_Click(object sender, ImageClickEventArgs e)
{
ImageButton Bt = sender as ImageButton;
GridViewRow GVRow = (GridViewRow)Bt.NamingContainer;
ID_lbl.Text = User_grd.DataKeys[GVRow.RowIndex].Value.ToString();
VoterName_txt.Text = GVRow.Cells[2].Text;
State_txt.Text = GVRow.Cells[3].Text;
District_txt.Text = GVRow.Cells[4].Text;
}
but when i run it the event is not Fired..What's the Problem?
Your issue is somehow the same that I encountered few months back. This might help you some way or another. try using LinkButton instead of Button...
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:gridview runat="server" id="GridView1" showfooter="true"
autogeneratecolumns="false" GridLines="None" CssClass="table1"
OnRowCreated="GridView1_RowCreated" BorderColor="#356600"
BorderStyle="Solid" >
<columns>
<asp:TemplateField HeaderText="Date" >
<ItemTemplate>
<asp:LinkButton ID="Date" runat="server"
CausesValidation="false" CommandName="Date_Select"
Text='<%#Eval("Date","{0:yyyy-MM-dd}") %>' onclick="Date_Click"
EnableTheming="False"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="Profit" headertext="Profit"
footerstyle-font-bold="true">
<FooterStyle Font-Bold="True"></FooterStyle>
</asp:boundfield>
</columns>
<HeaderStyle BackColor="#CEFF99" ForeColor="Black" BorderColor="#C1FF80"
BorderStyle="Solid" BorderWidth="1px"></HeaderStyle>
<RowStyle CssClass="td"></RowStyle>
</asp:gridview>
</ContentTemplate>
</asp:UpdatePanel>
protected void Date_Click(object sender, EventArgs e)
{
LinkButton Lnk = (LinkButton)sender;
Label1.Text = Lnk.Text; // This one works for me....
OdbcConnection con1 =
new OdbcConnection(ConfigurationManager
.ConnectionStrings["connect1"]
.ConnectionString);
OdbcCommand cmd = new OdbcCommand("select a.customer As Customer,a.mins as MIns,a.amount as Amount,a.profit as Profit from summarydatashort a,clientsrecord b where a.orig_clli=b.orig_clli and a.date='" + Label1.Text + "' and b.emplye='Ankit'", con1);
con1.Open();
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
da.Fill(ds);
con1.Close();
GridView17.DataSource = ds;
GridView17.DataBind();
}
I'm developing an Asp.net web site.
I'm using Ajax:ModalPopupExtender for displaying some information.
Html
<asp:UpdatePanel ID="upnlModelPopup" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Form control goes here...............
<asp:Button ID="btnShow" runat="server" CssClass="btn" Text="Adjustment" OnClick="btnShow_Click" Enabled="true" />
<cc1:ModalPopupExtender ID="mpeAdjAmt" runat="server" TargetControlID="lblHead"
PopupControlID="pnlMsg" BackgroundCssClass="displayHide"
DropShadow="true" OkControlID="lblStsFoot" OnOkScript="setFocus()" >
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlMsg" runat="server" CssClass="ErrorPanel" >
<table width="100%">
<tr>
<td >
<asp:Label ID="lblHead" CssClass="lblHead" runat="server"
Text=""></asp:Label>
</td>
</tr>
<tr>
<td >
<table class="tblTableHead" >
<tr >
<td style ="width:4%;">S.No</td>
<td style ="width:21%;">Type</td>
<td style ="width:25%;">Date</td>
<td style ="width:20%;">Amount Type</td>
<td style ="width:15%;">Amount</td>
<td style ="width:15%;">Adjust Amount</td>
</tr>
</table>
<div id="divGridStatus" style="width:100%;max-height:300px;overflow-Y:auto;overflow-X:hidden;" >
<asp:GridView ID="grvStatus" runat="server" Width="100%"
AutoGenerateColumns="false" CssClass="GridViewStyle" GridLines="None" ShowHeader="false" >
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkSNo" runat="server" CssClass="lbl"
Width="100%" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" >
<%# ((GridViewRow)Container).RowIndex + 1%>
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="4%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkwsid" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false"
Text='<%# Bind("wsid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="21%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnknm" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false"
Text='<%# Bind("nm") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="25%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkgrp1" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false" Text='<%# Bind("grp1") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="20%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkoptid" runat="Server" CssClass="lbl"
Width="100%" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" Text='<%# Bind("optid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkuid" runat="server"
Width="100%" CssClass="lbl" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" Text='<%# Bind("uid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="FooterStyle" />
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<EmptyDataTemplate>
No Data Found.
</EmptyDataTemplate>
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
</div>
<table class="tblTableHead" style="padding-left:1%;">
<tr>
<td>
<asp:Label ID="lblStsFoot" runat="server" Text="" ></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<br />
<%--OnClientClick="return CheckAdjustment();"OnClientClick="ShowWait();"--%>
<asp:Button ID="btnAdjust" runat="server" Text="Done" CssClass="btn" OnClick="btnAdjust_Click"
buttonAction="submitButton" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btn" OnClick="btnCancel_Click"
buttonAction="submitButton" />
</td>
</tr>
</table>
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
C# Code
protected void btnShow_Click(object sender, EventArgs e)
{
mpeAdjAmt.Show();
upnlModelPopup.Update();
}
protected void btnAdjust_Click(object sender, EventArgs e)
{
//Code goes here...
mpeAdjAmt.Hide();
upnlModelPopup.Update();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeAdjAmt.Hide();
upnlModelPopup.Update();
}
I'm showing/hiding this panel from code behind.
When i click's on show button first time it works very fine it shows panel proper.
My problem is when i click's on show button second time it doesn't show panel.
If i removed update panel it works fine when we use to show and hide panel from code behind but it starts flicker of panel on page load and works fine .
Can any one tell me what is the problem and how can i solve that.
Try doing
protected void btnShow_Click(object sender, EventArgs e)
{
mpeAdjAmt.Show();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
protected void btnAdjust_Click(object sender, EventArgs e)
{
//Code goes here...
mpeAdjAmt.Hide();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeAdjAmt.Hide();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
When I want to read e.CommandArgument then I get error saying "Input string was not in a correct format.". My markup portion is like bellow:
<asp:GridView ID="GridViewAllProducts" runat="server"
AutoGenerateColumns="False" GridLines="None"
AllowPaging="True" Width="100%"
EmptyDataText="هیچ محصولی پیدا نشد"
onrowcommand="GridViewAllProducts_RowCommand"
onrowdeleting="GridViewAllProducts_RowDeleting"
OnPageIndexChanging="GridViewAllProducts_PageIndexChanging">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div class='rowTableDiv rowAllNewsUC'>
<asp:HiddenField ID="hiddenId" runat="server" Value='<%# Bind("Id") %>' />
<img id="imgImage" src='<%# Bind("Image") %>' class="imgNewsAllNewsUC noBorder" alt="" runat="server" />
عنوان محصول: <asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label><br />
گروه: <asp:Label ID="lblCategory" runat="server" Text='<%# ProductC.GetProductCategoryName(Convert.ToInt32(Eval("CategoryId"))) %>'></asp:Label><br />
کد: <asp:Label ID="lblCode" runat="server" Text='<%# Bind("Code") %>'></asp:Label><br />
ابعاد: <asp:Label ID="lblDimention" runat="server" Text='<%# Bind("Dimention") %>'></asp:Label><br />
تعداد رنگ: <asp:Label ID="lblNumberOfColors" runat="server" Text='<%# Bind("NumberOfColors") %>'></asp:Label><br />
قیمت: <asp:Label ID="lblPrice" runat="server" Text='<%# nmsPublicClass.PublicClassC.ThousandSeparator(Convert.ToDecimal(Eval("Price"))) %>'></asp:Label>
<asp:LoginView ID="LoginView1" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Administrator">
<ContentTemplate>
<div class='rowTableDiv rowInfoAllNewsUC'>
<asp:Panel ID="pnlEdit" CssClass='colTableDiv' runat="server">
<div class='colTableDiv colInfoAllNewsUC'>
<asp:LinkButton ID="lbEdit"
CommandArgument='<%# Bind("Id") %>'
PostBackUrl='<%# String.Format("~/Page/Admin/InsertProduct.aspx?Mode=Edit&Id={0}", Eval("Id"))%>'
Font-Underline="false"
CommandName="edit"
runat="server">
<img id='img2' class='noBorder imgEditAllNewsUC' src="../../image/note_edit.png" alt="ویرایش" />
ویراش</asp:LinkButton>
<asp:LinkButton ID="lbDelete" CommandArgument='<%# Bind("Id") %>' Font-Underline="false" CommandName="delete" runat="server">
<img id='img1' class='noBorder imgEditAllNewsUC' src="../../image/delete.png" alt="حذف" />
حذف</asp:LinkButton>
</div>
</asp:Panel>
</div>
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
<div class="divHidden">
<asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataRowStyle CssClass="lblError" />
<PagerStyle CssClass="pagerGridView" />
</asp:GridView>
My code behind is like bellow:
protected void GridViewAllProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "delete")
{
int productId = Convert.ToInt32(e.CommandArgument);
string image = new ProductC().GetProductBy_Id(productId).Image;
Result r = new ProductC().DeleteBy_Id(productId);
if (r.IsSuccess)
{
File.Delete(Server.MapPath(image));
}
GridViewAllProducts.DataSource = new ProductC().GetAllProducts();
GridViewAllProducts.DataBind();
}
}
I get error "Input string was not in a correct format." at the following line:
int productId = Convert.ToInt32(e.CommandArgument);
What is the problem. Please help me. Thank you.
i have a gridview that show comments. i want that if a person likes a comment, press a like button and i increse the sum of likes , but i do not want to connect to database and bind. i want do that using ajax. how can i do that?
here is my code:
<asp:UpdatePanel runat="server" id="UpdatePanel" >
<ContentTemplate>
<asp:GridView ID="grdCommentsForLoginnedUser"
runat="server"
AutoGenerateColumns="False"
Width="100%"
OnRowCommand="grdCommentsForLoginnedUser_RowCommand"
ViewStateMode="Inherit">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="hdnCommentID" runat="server"
Value='<%# Bind("CommentID") %>'/>
<table border="2" dir="rtl">
<tr>
<td rowspan="2" style="background-color: #6699FF" width="200px">
<asp:HyperLink ID="lnkCommenterName"
runat="server"
NavigateUrl='<%# Bind("CommenterProfile") %>'
Text='<%# Bind("CommenterName") %>' />
</td>
<td width="700px">
<br />
<asp:Label ID="lblCommentText" runat="server"
Text='<%# Bind("CommentText") %>' />
<br />
</td>
</tr>
<tr>
<td width="700px">
<asp:Label ID="lblPreviousAcceptOrNonAccept" runat="server"
Text='<%# Bind("PersonPreviousAcceptOrNonAccept") %>' />
<asp:LinkButton ID="lnkBtnRemovePreviousAcceptOrNonAccept"
runat="server"
Text='<%# Bind("RemovePersonPreviousAcceptOrNonAccept") %>'
CommandName="RemovePreviousAcceptOrNonAccept"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />
<asp:LinkButton ID="lnkBtnUpRate" runat="server" Text="Like"
Visible='<%# Bind("isLikeAndUnlikeButtonVisible") %>'
CommandName="LikeComment"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />sum of likes
<asp:Label ID="lblCommentLikes" runat="server"
Text='<%# Bind("CommentLikes") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Add a client side onClick javascript to each button. When clicked get the parent td tag and then getElementById("lblCommentLikes") to set the .innerText property of the "lblCommentLikes" span.
+(theTD.getElementById("lblCommentLikes").innerText)+=1;
or
+(theTD.getElementById("lblCommentLikes").innerText)-=1;
Tip: If you are using IE then press F12 to inspect the DOM of a running page
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="OfferID" GroupItemCount="2" >
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="groupPlaceholderContainer" runat="server" border="0" style="">
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<td runat="server" style="">
<div id="wrapper">
<div id="ResImage">
<div id="slideshow">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval ("Image1") %>' Width="250px" Height="190px" CssClass="active" />
<asp:Image ID="Image5" runat="server" ImageUrl='<%# Eval ("Image2") %>' Width="250px" Height="190px" />
<asp:Image ID="Image4" runat="server" ImageUrl='<%# Eval ("Image3") %>' Width="250px" Height="190px" />
</div>
</div>
<div id="ResDesc">
<asp:Label ID="lblDesc" runat="server" Width="290px" Height="190px" BackColor="White" Text='<%# Eval("Offer") %>'></asp:Label>
</div>
<div id="ResPrice1">
<asp:Label ID="lblValue" runat="server" Text="Value" CssClass="ResValue"></asp:Label>
<asp:Label ID="lblDiscount" runat="server" Text="Discount" CssClass="ResDiscount"></asp:Label>
<asp:Label ID="lblYouPay" runat="server" Text="You Pay" CssClass="ResYouPay"></asp:Label>
<div id="ResPrice2">
<asp:Label ID="lblValueAmt" runat="server" Text='<%# Eval("Value") %>' CssClass="ResValueAmt"></asp:Label>
<asp:Label ID="lblDiscountAmt" runat="server" Text='<%# Eval("Discount") %>' CssClass="ResDiscountAmt"></asp:Label>
<asp:Label ID="lblYouPayAmt" runat="server" Text='<%# Eval("YouPay") %>' CssClass="ResYouPayAmt"></asp:Label>
</div>
<asp:Label ID="lblRestaurantName" runat="server" Text='<%# Eval("RestaurantName") %>'></asp:Label><br />
<asp:LinkButton ID="lnkGetCoupon" runat="server">Get Discount Coupon</asp:LinkButton>
</div>
<div id="HowItWorks">
<asp:Label ID="lblHowItWorks" runat="server" Text="How It Works?" Font-Bold="True" Font-Size="Small" ForeColor="Red"></asp:Label>
<ul>
<li><asp:Label ID="Label3" runat="server" Text="1.Click on the 'Get Discount Coupon' button" Font-Size="10px"></asp:Label></li>
<li><asp:Label ID="Label4" runat="server" Text="2.Get a print of your Voucher and carry it during your visit to the outlet." Font-Size="10px"></asp:Label></li>
<li><asp:Label ID="Label5" runat="server" Text="3.Show your Voucher and pay the amount directly to the merchant. " Font-Size="10px"></asp:Label></li>
</ul>
</div>
<asp:Label ID="OfferID" runat="server" Text='<%# Eval("OfferID") %>' Visible="false"></asp:Label>
</div>
</td>
</ItemTemplate>
How to find the label control with the id=OfferID...how to use findcontrol here??
i want to find the OfferID of the row on which i click...i have a linkbutton lnkGetCoupon..when i click on the link button...i want to pass the OfferID in the query string to the next page.
i am a new user so they do not let me post answer to my own question
heres the answer...
i added CommandArgument='<%# Eval("OfferID") %> to the link button.
<asp:LinkButton ID="lnkGetCoupon" CommandArgument='<%# Eval("OfferID") %>' runat="server">Get Discount Coupon</asp:LinkButton>
and used the ListView1_ItemCommand
Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand
Dim offer As String
offer = e.CommandArgument.ToString()
Dim url As String = "~/RestaurantDedicatedPage.aspx?offerID=" + offer
Response.Redirect(url, True)
End Sub
You don't need the Label at all, you can get the OfferID from the DataKeys collection.
First, add a CommandName to your LinkButton:
<asp:LinkButton ID="lnkGetCoupon" runat="server" CommandName="GetCoupon">Get Discount Coupon</asp:LinkButton>
Then use it in the ItemCommand handler:
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "GetCoupon")
{
ListViewDataItem item = (ListViewDataItem)e.Item;
int index = item.DataItemIndex;
string offerID = ((ListView)sender).DataKeys[index]["OfferID"].ToString();
Response.Redirect("yourUrl" + offerID);
}
}
Attach to the ListView.ItemCommand event and within that event you can search on the Item in the ListViewCommandEventArgs to find the control you need to alter.
Update your ListView in your ASPX to hook up the ItemCommand event:
<asp:ListView ... OnItemDataBound="ListView1_ItemCommand">
<ItemTemplate>
...
<asp:LinkButton id="lnkGetCoupon" CommandName="View" CommandArgument="<%# Eval("OfferID") %>" />
...
</ItemTemplate>
</asp:ListView>
The ItemCommand event will be fired when a Button or LinkButton (or some other button-esque control) is clicked. To handle this event, add the following
code to your *.aspx.cs (code-behind) file:
protected void ListView1_ItemDataBound(object sender, ListViewCommandEventArgs e)
{
//Check if the lnkGetCoupon button was clicked.
if (string.Equals("View", e.CommandName))
{
//Get the offerID from the CommandArgument.
int offerID = int.Parse(e.CommandArgument);
//Perform your logic using the offerID
}
}