Button List inside the DataList control - c#

I am a facing a situation in which I need to use something like a ButtonList inside a DataList control.
Since there is no control like ButtonList, should I nest a DataList/Repeater inside the DataList or there is some other better option to handle the situation.

I am not exactly sure what you are looking for but this is what I assume you want:
YourListItem1
ButtonAction1
ButtonAction2
ButtonAction3
ButtonAction4
YourListItem2
ButtonAction1
ButtonAction3
YourListItem3
ButtonAction1
ButtonAction2
YourListItem3
ButtonAction3
ButtonAction4
Or something similar?
To produce this you could just have a DataList with a Repeater inside that contains the buttons you need. You could implement the OnDataBinding event of your DataList (YourListItem) and then bind the data that produces the buttons based on some data. Then in the Repeater you could implement each button's OnDataBinding event and assign the CommandArguments with the ID or detail you need to make the button act specific to the row it is on.
This method would allow you to make one function for each button used in your template and the CommandArgument would define the details of the action.

Related

How to make a User Control that behaves like a combobox but with an editable textbox

I want to make a Searchbox, so i want to create a User Control, that display a textbox but when typed on will call a dropdown list similar to that of a combobox. ¿is this posible?
the input that you are describing called AutoComplete,
and WPFToolkit suggest easy to use one
https://github.com/dotnetprojects/WpfToolkit

How can I print repeater data in asp.net?

How can I print Repeater data?
I am having a Search page which makes search query according to the input given and populate the repeater. Now I want to print this result displayed in the repeater. How can I do that on the onClick button event of a "Print" asp:Button?
If you want to provide search capability, follow below steps-
If you are filling repeater on PageLoad with whole data, remember to prevent your repeater binding always on PageLoad using IsPostBack property.
Now on Click event get the filtered data, and bind it with repeater.
Hope this will solve your problem, If need any help please update your question with code.
Thanks.

how to access dynamically added radiobutton in update panel

ive product detail page , ive radiobutton in this page which i created dynamically in an updatepanel because of postback... i created it very well , there is an checkedchanged event for all radiobuttons it works very well but i need to get radiobutton text value but i cant reach the radiobutton, it looks as control in updatepanel... but here thing at least for me:D... after i deleted update panel i can reach radiobuttons easily... why it happens like this , i couldnt understand... but i know something i need to prevent page postback on radiobuttons checkedchanged event so how can i do this by using ajax or updatepanel something...
thx...
You said that you can reach radiobutton but it looks like a control. I think you access like that:
myUpdatePanel.Controls[0] // or in a foreach or something like that
What about cast each of that controls?
var myRadioButton = (RadioButton)myUpdatePanel.Controls[0];

Is it possible to put another element (button) inside a Checkboxlist Item?

I have a CheckBoxList that is populated via DataSource (each one with it's value coming from a database so I can't hard-code anything inside it), and I need to Add a button for details on the right side of an specific Item of the CheckBoxList when some event is fired.
Can i do that? how?
Each item in the CheckBoxList is a ListItem object. These don't inherit from Control so they don't have their own ControlCollection property. This means you can't add a LinkButton or Button to the item(s).
If it was based on a Control object, you'd be able to hook into the OnDataBound event of the CheckBoxList, and iterate through the items until you find the one that needs the button. From there you'd be able to add the control (button) to the individual item's item.Controls collection. But you're going to be pretty limited for the ListItem because it doesn't have this functionality.
What does the details button do? If it's simply a client-side button, you could maybe inject html into the Text property of the ListItem, although I haven't verified this works:
foreach (ListItem item in myCheckBoxList)
{
item.Text += " <input type=\"button\"/>";
}
Either way it won't be pretty, and you might be better to create a simple user control. In the control you could still use a CheckBoxList, but you could add HyperLink or Buttons to the UserControl dynamically. You could use CSS or other means to lay out the button in the right spot.
You will have to write a custom user control if you want to do that.

How do I add response from TextBox? c#

I have created my own control which contains TextBox control as a child control. this textbox has autopostback set on. when the postback is called I dont get any text in request.querrystring.
where should I specify text entered into texbox will be send to response ? or is there any easier way of sending this information? I want to have the entered text once again in textbox after postback.
thank you
For dynamically created controls, you need to create them and add them to the control tree in the Page_Init() event; Page_Load() is too late, and Page_PreRender() is way too late.
Once in the control tree, the runtime will restore the state of the control for you after a postback. You can access the contents of the control using myTextBox.Text -- you don't need to use Request.QueryString
For a control that only contains a TextBox, things would be much easier if you used a user control rather than an INamingContainer. That way, you could just use <asp:TextBox> in your .ascx markup.
A custom control? Any posted control like this loads its data in LoadPostData method. You can override this in your custom control class, and access the value from teh control via:
var text = postDataCollection[textboxID];
The textbox within your custom control has to have an ID.
If you are talking something else, let me know the specifics.
Thanks.
(TextBox)Control.FindControl("control id")
get dynamic control's value in postback , Request.Form("control client id")

Categories

Resources