I have a repeater which displays products. Users can select a Size - dropdownlist and an Amount - textbox. Then they press Order or Cancel. When they press Cancel I would like the values of Size and Amount to return to their default values.
Protected Sub lbtnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnCancel.Click
rpt.ProductList is the repeater name
lblFeedback.Text = ("")
lblFeedback.ForeColor = Drawing.Color.Black
End Sub
Any help is welcome!
I am using VB.NET.
What if you rebind your repeater on the Cancel Click, so it will again be populated with your Default Values ?
Use the rptProductList_ItemCommand event to catch the repeateritem line and play with the controls as you please ...
Related
Wasn't able to find anything about this situation:
I have two RadDatePicker inside RadGrid for start and end date change
<telerik:RadDatePicker ID="rdpStartDate" Skin="Library" EnableEmbeddedSkins="false" CommandName="StartDateChange" runat="server" />
By itself, they work fine, but now I have a situation when I need to call method when their value has been changed (CommandName was added for this)
I know how to do this outside RadGrid, basically:
Protected Sub rdpStartDateChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs) Handles rdpStartDate.SelectedDateChanged
...
...
End Sub
But I wasn't able to do this inside RadGrid, because nothings seems to trigger it.
I tried to catch my command with this (works for buttons at least):
Protected Sub rgLibraryItemCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) Handles rgLibrary.ItemCommand
But, no, it doesn't see CommandName="StartDateChange"
What I need to do to be able to catch those Date change events if RadDatePicker
is placed inside RadGrid?
You need to identify the control inside the grid which triggers the action. I'm not sure which is the way for Rad to do that but it should be similar this:
Private Sub DataGridView1_ButtonClick(sender As DataGridView, e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellButtonClick
'TODO - Button Clicked - Execute Code Here
End Sub
So you need to find the events for the DataGridViewRow for Rad and substitute them with the ones cell clicking events. This example should get you started.
Subscribing to an event on a control inside a RadGrid does not work the same way, because there could be multiple copies of the control or even none at all, depending on how many records are in the Data Source. Therefore, in order to subscribe to events on these controls, you have to do it manually after the data is bound, either in the ItemCreated event or ItemDataBound event.
Protected Sub rgLibraryItemCreated(ByVal sender as Object, ByVal e As GridItemEventArgs) Handles rgLibrary.ItemCreated
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = e.Item
Dim rdpStartDate As RadDatePicker = item.FindControl("rdpStartDate")
AddHandler rdpStartDate.SelectedDateChanged, AddressOf rdpStartDateChanged
End If
End Sub
I have a user control that creates a grid view of database records. Each record has a checkbox for deleting the record.
My problem is that the the page_load event builds the grid view, then the delete button even fires. The deleteButton_click event is looping over the gridview looking for checked boxes but never finds any because the 'page_load' event just gave me a clean gridview. What is the best way to check for checked boxes before the grid view is re-built? Or can I get the checked values without looking at the grid view?
Protected Sub Page_Load(...) Handles Me.Load
'db calls and other code
gv.DataBind()
End Sub
Protected Sub btnDelAtt_Click(...) Handles btnDelAtt.Click
For Each grdRow As GridViewRow In gvFileViewer.Row
Dim chkBox As CheckBox = CType(grdRow.FindControl("cbItem"), CheckBox)
If chkBox.Checked = True Then 'this is always false thanks to page_load
'code that does not run
end if
next
end sub
As mentioned in the comments, adding !IsPostBack should do it.
You only need to load the grid from the database in the initial call, you don't need to get the data again when post back occurs. You will need to rebind the grid once the delete is over.
Protected Sub Page_Load(...) Handles Me.Load
If(!Page.IsPostBack)
'db calls and other code
gv.DataBind()
End Sub
Protected Sub btnDelAtt_Click(...) Handles btnDelAtt.Click
For Each grdRow As GridViewRow In gvFileViewer.Row
Dim chkBox As CheckBox = CType(grdRow.FindControl("cbItem"), CheckBox)
//Delete your record
end if
next
//Rebind grid
end sub
I have a page with GridView. The GridView has select button. Normally I use GridView's selected index changed event to do all kinds of operations when user clicks select button. But now I want to do some operations in Page_Load event based on grid view's selected row. Since the Selected_Index_changed event occurs after Page_Load how do I know following things in page load event.
I checked the asp lifecycle and this other question but I dont know how to do this.
How about using a QueryString to transmit which row was selected and then in the Page_Load event get the QueryString parameters? This is an example.
Protected Sub LinkButton1_Command(sender As Object, e As CommandEventArgs)
Dim UserId As Integer = e.CommandArgument 'Here goes whatever value you're trying to pass
Response.Redirect("~/OtherPage.aspx?UserId=" _
& UserId)
End Sub
This is in the OtherPage.aspx
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
UserId = Request.QueryString("UserId")
'Your code
end sub
I have a gridview in my website in am building in Visiual studio 2010. IM new to programming and have a query in reference to redirecting the user to another page based on the results of the gridview.
My gridview works perfectly fine and pulls back items via a selection made in a dropdown list. These items have and id assigned (1 for Weekly & 2 for Monthly).
My users selects the Weekly or Montly option from the dropdown and the grid view is populated with this data. (This part works perfectly fine).
Once the results are displayed i want the user to then press the 'Create' button and for them to be directed to the correct Weekly.aspx or Monthly.aspx page based on the selected item from the dropdown list.
So far i have the following code which seems to redirect the user to the Monthly.aspx page for either selection from the dropdown list.
Protected Sub btnCreate_Agenda_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreate_Agenda.Click
If DropDownList1.SelectedItem.Equals("1") Then
Response.Redirect("Weekly.aspx")
Else
Response.Redirect("Monthly.aspx")
End If
End Sub
Can anyone point me in the right direction?
In my page load event i would also like to make sure that for the webpage item 1 (Weekly) is the default selection. I have tried doing this by adding the following code to the page_load event but i have no just with the results.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.SelectedItem.Equals("1")
End Sub
You need to assign the value to the dropdown or choose the index of the item, not compare the current value to something.
DropDownList1.SelectedValue = "1"
Or
DropDownList1.SelectedIndex = 1
The SelectedItem property will return a ListItem object, so that will never be equal to the string "1". Use the SelectedValue property instead:
If DropDownList1.SelectedValue = "1" Then
Response.Redirect("Weekly.aspx")
Else
Response.Redirect("Monthly.aspx")
End If
Regarding setting the default, the SelectedItem property is a read-only property. Use the SelectedIndex or SelectedValue properties to select an item:
DropDownList1.SelectedValue = "1"
how to remove the record from gridview when i click on delete button in vb.net ?
Gridview has an event called 'RowDeleting' which you can use to handle Delete events.
For example:
Private Sub gridview_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gridview.RowDeleting
'' Handle your delete here and rebind your datasource if needed
End Sub