issue in gridview[checkbox and images] - asp.net

' />
'/>
this is my code where i am trying to display checkbox and images
my table has columns
itemID Imagespath
1 item1.jpg
2 item2.jpg
3 item3.jpg
4 item4.jpg
but in output it is showing as i want to show only checkbox and image
but now it is showing checkbox along with the [ID i.e 1 ,2,3 etc ] which i should make as [ID as invisiable in design but in code behind i should be able to get the selected value ID]
is there ant way i can remove the gridview border and row border.
actually i am trying to amke a checkboxlist alaong with the images, right now even images are not getting displayed
thank you

You can leverage the GridView's DataKeys property for this:
<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID">
In your code you can loop through the rows and read the data key for that row and get the checkbox like this:
foreach (GridViewRow gvr in gvImages.Rows)
{
int CustomerID = (int)gvImages.DataKeys[gvr.RowIndex].Value;
CheckBox CheckBox1 = (CheckBox)gvr.FindControl("CheckBox1");
}

Text property of Checkboxes not used for server side value. Checkboxes don't have a value property. They have only Checked property for value.
In your case you should add an hidden field in your row that will hold the value of ID column, and you can get it at server side.

Related

Adding Item at first Index of Database-bound DropdownList in DetailsView

I have a DetailsView on an ASP-Webform with several DropdownLists bound to ForeignKey-Tables. I want to add something like "Please choose..." at the first index of Items. I´m using DataBound-Event of Dropdown to add this ListItem with the shown Text and Value = 0. But the "Please choose..."-Item is always at the last index of the Items.
How can I do to get it at the first Index?
You can write
ddl.Items.Insert(0,new ListItem("Please Choose","0"));
ddl is your DropDownList ID

Why is my RadioButtonList selectedValue empty?

I have a RadioButtonList:
<asp:RadioButtonList ID="rblMedicationTime" runat="server" onselectedindexchanged="rblMedicationTime_SelectedIndexChanged" DataSourceID="dtsMedicationTime" DataTextField="LookupItem" DataValueField="Id" AutoPostBack="true"></asp:RadioButtonList>
On page load, I want to select a radio button from the list and set its value, for which I have written this line of code:
rblMedicationTime.SelectedValue = clientMedicationSchedule.glTypeId.ToString();
The RadioButtonList is populating successfully, but the value is unable to be selected.
rblMedicationTime.SelectedValue is always "" when I debug the code.
You just need to use
string myValue = myRadioButtonList.SelectedItem.Value
The property object myRadioButtonList.SelectedItem contains all values from the selected item of a Radio Button list or a DropDown list
to set the value programmatically all you have to do is:
myRadioButtonList.SelectedIndex = 0;
You can see that you have several ways to Get but only one to Set:
myRadioButtonList.SelectedIndex --> Gets or Sets
myRadioButtonList.SelectedValue --> Gets
myRadioButtonList.SelectedItem --> Gets
You can't set the selected radiobutton with .SelectedValue, only with .SelectedIndex.
Check MSDN (at SelectedValue it says "Gets the value", at SelectedIndex is says "Gets or sets")
I think problem in !IsPostBack.
if (!IsPostBack)
{
string str = rblMedicationTime.SelectedValue;
}
First you should check !IspostBack
hello friend there is something another problem in your code because in my side this is running fine.
rblMedicationTime.SelectedValue = clientMedicationSchedule.glTypeId.ToString();
can u cehck that clientMedicationSchedule.glTypeId.ToString() this contain value or not.
and on page load u put selection code on if (!IsPostBack){} block.

How to put values in textbox from listbox in jQuery MVC ASP.NET

I have one Listbox named "List1" and one button says "Append".
I have on textbox named "TextDescription".
I want to put the select values from the listbox to textbox on click of append button.
So can anyone tell me how to do this?
You could use the .val() function. So assuming you have a select with id="myselect" and a text input with id="mytext" you could do this:
var values = $('#myselect').val();
if (values != null) {
// concatenate the selected values with , so that we can add them to the textbox
$('#mytext').val(values.join(','));
}
And here's a live demo illustrating it in action.

tooltip in asp.net

I have a gridview for which I am binding data from a Generic List collection. Currently not connected to DB. All the columns in the GridView are defined as properties(get;set.
I want to have tooltip on one of the columns. The column has a very big description. I want to show only 3 words in the column and the rest of the description should appear in tooltip.
Currently my gridview has only asp:gridview id and runat server
There are no columns, headertemplate and itemtemplate.
Could anyone suggest some idea on this.
Thanks in advance
Well, I don't know how you are getting your columns in place...but I suppose you could put a Label webcontrol in the itemtemplate for the header of each column, and give that label's tooltip property the value you want it to have.
Seems to me like that would be a pretty viable solution for this, if I'm understanding you correctly..
You can use an itme template with a label as mentioned. Bind the label the full description:
<ItemTemplate>
<asp:Label id="l1" runat="server" Text='<%# Eval("Description")' />
</ItemTemplate>
In code-behind, use RowDataBound to process each row accordingly:
protected void RowDB(..)
{
Label l = e.Row.Cells[4].Controls[1] as Label;
if (l == null) return;
string description = l.Text;
l.Text = //Partial text here
}
And the grid will bind each row, the full text is passed to a variable, and you can insert a substring of the text (3 words or such) by assigning the new value to the text property.
What kind of tooltip are you looking for? You could use the tooltip property, or consider using the ACT HoverMenuExtender: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx

ASP.NET: Gridview Showing a button on a row, when a row cell vlaue = false in the Bound row from the database

I have a GridView binded to a datasource, i was wondering of how i can check a row cell value (bool) from the database row being bound , and then show a button on the rows where the cell value equals to false..
i am using OndataBound Event to retrieve the Gridview-row being bound, i take the ID show, run another procedure against the database to find the value of the cell from the corresponding Database row..
but i cant figure out how to add the button..
also is there any other ways to handle this scenario?
Solution 1: Create a button with an ID where you want it in the gridview, with an attribute visible=false. Whenever you want to show the button, retrieve it (currentGridRow.FindControl("chosen button ID")) and set it's visible attribute to true.
put your button in a templatefield, like that:
<asp:TemplateField HeaderText="foobar" >
<ItemTemplate>
<asp:ImageButton ID="plusbutton" CssClass="cplusButton" ToolTip="plusButton" OnClick="buttonAdd_Click" runat="server" Visible = "false"/>
</ItemTemplate>
</asp:TemplateField>
Solution 2: dynamically create the button (Button b = new Button; currentGridRow.Cell[].Controls.Add(b);), but it's a pain to deal with the viewstate and the events handler. Don't go that way.

Resources