Bit of help with DataPager template & LinkButton please? - asp.net

I have a datapager with a pagertemplate. In the template I have a "Show All" button, which sets the PageSize of the datapager to show all records. This works fine but I want to be able to hide the button when it's clicked. It's in an UpdatePanel so I don't know if that makes a difference?
<asp:DataPager ID="Pager" runat="server" PagedControlID="rangeList" PageSize="15" EnableViewState="false">
<Fields>
<asp:TemplatePagerField>
<PagerTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="<%# Container.TotalRowCount.ToString() %>"
oncommand="LinkButton1_Command" >Show All Ranges</asp:LinkButton>
</PagerTemplate>
</asp:TemplatePagerField>
<asp:numericpagerfield ButtonCount="10" NextPageText="..." PreviousPageText="..." CurrentPageLabelCssClass="pageOn" />
</Fields>
</asp:DataPager>
And the codebehind:
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
this.Pager.PageSize = int.Parse(e.CommandArgument.ToString());
LinkButton lb = (LinkButton)sender;
if (lb != null)
{
lb.Visible = false;
}
rangeList.DataBind();
}
The first click works fine, and refreshes the ListView which in turn adjusts the pager to show one page with all the results on it, but the button doesn't disappear as I want it to.
Any ideas?

If there's nothing to display within the pager, why not hide the Pager control itself:
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
this.Pager.PageSize = int.Parse(e.CommandArgument.ToString());
this.Pager.Visible = false;
lnkShowPages.Visible = true; // EDIT only
rangeList.DataBind();
}
EDIT:
You could have a second "Show Pages" LinkButton that's initially not visible and becomes visible when the Show All LinkButton is clicked (above). When this new LinkButton is clicked, it could then enable paging by setting the Pager's PageSize and visibility and hiding itself:
protected void lnkShowPages_Command(object sender, CommandEventArgs e)
{
this.Pager.PageSize = int.Parse(e.CommandArgument.ToString());
this.Pager.Visible = true;
lnkShowPages.Visible = false;
rangeList.DataBind();
}

Related

Radio Button inside grid view control not firing oncheckedchanged event

I have following code in my application I have a gridview control insde my grid view I have radio button defined as templetefield.
<asp:View ID="View3" runat="server">
<script type = "text/javascript">
function RadioCheck(rb) {
var gv = document.getElementById("<%=grdAllPartsRequestList.ClientID%>");
var rbs = gv.getElementsByTagName("input");
var row = rb.parentNode.parentNode;
for (var i = 0; i < rbs.length; i++) {
if (rbs[i].type == "radio") {
if (rbs[i].checked && rbs[i] != rb) {
rbs[i].checked = false;
break;
}
}
}
}
</script>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rbSelected" runat="server" AutoPostBack="True"
oncheckedchanged="rbSelected_CheckedChanged" GroupName="RequestSelection" onclick="RadioCheck(this);" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</<asp:View>
Code Behind .CS
protected void rbSelected_CheckedChanged(object sender, EventArgs e)
{
}
Now my problem is upon running my page when I click the radio button the Event doesn't fire. oncheckedchanged is not firing.
Surprisingly The same functionality works fine in another page with in the grid view.
I have searched the web for this answers. But so far nothing worked out. I have Update Panel in my Master Page.. I have tried to play with UpdateMode="Always" and ChildrenAsTriggers="true" but so far nothing worked out please help!
Try this,
void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
Radiobutton rb = e.Row.FindControl("rbSelected") as Radiobutton;
rb.oncheckedchanged += this.rbSelected_CheckedChanged;
}
}
The event will be added to the radiobutton on rowdatabound event of GridView...
Hope this helps you...

set button visibility in code behind aspx.net

How can I set in my button_Click event, visibility of button in gridView to false?
All the time it give me an error:Compilation Error
Compiler Error Message: CS0103: The name 'btnTest' does not exist in the current context
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button189" OnClick="Button189_Click" runat="server" Text="odzemi svez vrganj" />
<asp:Button ID="btnTest" runat="server" CommandName="odzemi" CssClass="button2" OnClick="btnTest_Click" Text="-" Width="100px" Font-Bold="True" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Following is my button event from where i want to hide button inside gridview.
protected void Button10_Click(object sender, EventArgs e)
{
btnTest.Visible = true;
Button189.Visible = false;
}
Use following code to set button visible property to True or False . The Button in gridview which will be clicked will act as sender. Doing so will give you the row id where the button is fired from and then you can find other controls and set your desired property on that particular row.
protected void Button189_Click(object sender, EventArgs e)
{
Button Btn = sender as Button;
GridViewRow gvRow = Btn.NamingContainer as GridViewRow;
int rowId = gvRow.RowIndex;
Button Button189 = GridView2.Rows[rowId].FindControl("Button189") as Button;
Button btnTest = GridView2.Rows[rowId].FindControl("btnTest") as Button;
Button189.Visible = false;
btnTest.Visible = true;
}
You need to loop through the gridview rows and find the control
foreach (GridViewRow row in grid.Rows)
{
if(row.RowType == DataControlRowType.DataRow)
{
var control = ((Button)row.FindControl("btnTest"));
if (control != NULL)
{
((Button)control).Visible = false;
}
}
}

Click Event for ImageButton Inside RadGrid

I have an asp.net ImageButton inside a RadGrid (in a column) that when clicked opens a popup window. I can also expand this same RadGrid to reveal a nested grid. I have a button inside here that I need to assign a click event to such that it opens the same popup. How do I fire off an ImageButton click that's housed inside a RadGrid?
Here is the aspx and the "imgEdit" is what I need to fire off:
<MasterTableView DataKeyNames="SuggestionID">
<EditFormSettings CaptionFormatString="Edit Suggestion: {0}" CaptionDataField="Title"
InsertCaption="Add Suggestion" EditFormType="WebUserControl" PopUpSettings-Width="655px"
UserControlName="~/CommonUserControls/SuggestionControl.ascx">
</EditFormSettings>
<Columns>
<telerik:GridTemplateColumn UniqueName="EditAction" HeaderStyle-Width="32px" ItemStyle-Wrap="false"
Resizable="false">
<ItemTemplate>
<asp:ImageButton ID="imgEdit" runat="server" CommandName="Edit" Resizable="false"
ImageUrl="/ESDNET/Images/Icons/pencil.png" ToolTip="Edit Suggestion" Visible='<%# Eval("CanEdit") %>' />
You can achieve the same in different ways:
1) Directly attach the button click event of imagebutton
protected void imgEdit_Click(object sender, ImageClickEventArgs e)
{
// your code
}
2) Using CommandName:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if(e.CommandName=="Edit")
{
}
}
3) If the commandname is Edit ,then it will autometically fire EditCommand
protected void RadGrid1_EditCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
}

Need help asp.net other textbox

In my project i have kept source info in dropdownlist. Like source of info: in dropdownlist three items website, Newspaper and others. If user select Others item, then only other text box should be visible otherwise should be invisible. For that i have set in page load event
lblother.visible=false;
txtother.visible=false;
And in Btnsubmit event i have written the condition like.
if(dropdownlistinfo.selectedindex==2)
{
lblother.visible=true;
txtother.visible=true;
}
But in my case i m not getting my desire output. Its always invisible when i am selecting Others item from drowdownlist also. Pls somebody help me where is my mistake?
Thanks,
Sumit
I think the problem is here.
if (!IsPostBack)
{
lblother.visible = false;
txtother.visible = false;
}
This will work if you set Selected property of the default list item.
<asp:DropDownList ID="DropDownList" runat="server">
<asp:ListItem Text="Website" Selected="True"></asp:ListItem>
<asp:ListItem Text="Newspaper"></asp:ListItem>
<asp:ListItem Text="Other"></asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblOther" runat="server" Text="Other"></asp:Label>
<asp:TextBox ID="txtOther" runat="server"></asp:TextBox>
Hide the controls in the Page Load event.
protected void Page_Load(object sender, EventArgs e)
{
this.txtOther.Visible = false;
this.lblOther.Visible = false;
}
Then show the controls in the button click event.
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 2)
{
this.txtOther.Visible = true;
this.lblOther.Visible = true;
}
}

details view with Dropdownn control

in the modal pop up i am using detailsview control by default all the data would
be shown in label.
there will be an edit button down once the user clicks edit button all the lablel would be gone and text box and dropdown control should be present so that user can change the values and again update into database
looking forward for a solution. i dnt want to use sqlDatasource. i wanted it to do in .cs
thank you
here is how to:
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" />
</EditItemTemplate>
protected void DetailsView1_DataBound(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
DropDownList ddl = DetailsView1.FindControl("DropDownList1") as DropDownList;
if (ddl != null)
{
ddl.DataSource = dataSource;
ddl.DataBind();
}
}
}

Resources