Get DropDownList Selected Value by Selected Text - vb.net

Do anyone knows how to get selected value of a drop down list by selected text?
I tried the below method but doesn't work:
ddlWorkType.SelectedItem.Text = "writing"
myddlvalue = ddlWorkType.SelectedValue
Please show me how. Thanks.

DDLResp.Items.FindByText(TxtResp.Text.Trim).Selected = True
Try this Code

how to get selected value and selected text in vb.net
<asp:DropDownList CssClass="textbox" ID="ddlUser" runat="server">
<asp:ListItem Value="0">Select User</asp:ListItem>
</asp:DropDownList><br />
Selected DropDownList value
ddlvalue = ddlUser.SelectedItem.Value
Selected DropDownList text
ddlText = ddlUser.SelectedItem.Text

Selected text is actually text which you selecting through mouse drag or by press shift key to copy/paste or delete text. You need to use just .Text instead of .SelectedText
ddlWorkType.Text = "writing"
myddlvalue = ddlWorkType.SelectedValue
if the text does not exist in assign datasource then combobox SelectedIndex will return -1 and SelectedValue will return Nothing.

Related

vb.net html input placeholder

HTML Code
<input placeholder="0000000000" type="text" name="msisdn" id="msisdn">
i've tried innertext by this code :
WebBrowser1.Document.GetElementById("msisdn").InnerText = TextBox1.Text
but it change the placeholder value not the inner text of textbox
i want to change the exact text value of textbox not the placeholder value
Try this:
WebBrowser1.Document.GetElementById("msisdn").SetAttribute("value", TextBox1.Text)
You're looking for the .value property.
innerText is for content; <input> elements don't have content.

How to get gridview clickable cell data value to new page aspx

I have two columns in a GridView where every cell of 1 column is hyperlinked.
<asp:GridView ID="gvBlogList" runat="server" DataKeyNames="Id"
AutoGenerateColumns="False" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLinkField DataTextField="id"
HeaderText="Blog id" NavigateUrl="detailspage.aspx" />
</ItemTemplate>
<ItemStyle Width="150px"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
How can I get cell value in 2nd page as a session variable?
Thanks!
As per the what I understand from your question, you want to catch the value of the cell that is clicked, store it in session and make it accessible on the page that have redirect to. This is possible and you can try a flow like this :
You can use the GridView's inbuilt method onRowCommand in this case to generate a server side event and you can then identify which cell was clicked and lastly, you can get its value by index. The below code is a demonstration that you can try and manipulate as per your requirement. This is a sample where a Linkbutton is used in Gridview and on the click of it, its value is fetched.
You can also try to use the CommandName and CommandArgument properties if you want to assign that particular control a value that you may use at the server side.
protected void Grd1_RowCommand(object sender, GridViewCommandEventArgs e)
{
LinkButton lnk = (LinkButton)e.CommandSource;
string value = lnk.Text;
}
And for storing it in Session, you just have to make use of Session["yourVarName"] = value;. And this value can be accessed on the other page.
Hope this helps.

How to bind the value from textbox to datagrid and datagrid to textbox in vb.net?

i have a datagrid, need to bind the value from textbox to datagrid using add button,
If i double click the datagrid the values want to bind in textbox. after modify the data in text box i need to replace the value for existing data in datagrid.
Like this for textbox to datagrid
<asp:TextBox ID="txtLocation" runat="server" Text='<%# Eval("Location") %>' />

ASP.net VB Listbox

I've seen many questions around this one, but none hitting it directly.
I put a listbox on a page and populate it with three items from an Access database. I have a button on that page that will extract several values including the selected item from the listbox. Or I want to anyway.
I can see the item selected in windows (highlighted) when I click the button, but when I try to select it no item is available as selected in the listbox. The ListBox1.SelectedIndex is alway -1.
Here is the code from the page:
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Text="List1" />
<asp:ListItem Text="List2" />
<asp:ListItem Text="List3" />
</asp:ListBox>
Is there a property missing?
Here is the code from the code behind page:
Public Function getDept() As String
Dim dept As String
If ListBox1.SelectedIndex > -1 Then
dept = ListBox1.SelectedItem.Text
Else
dept = "CMS"
End If
Return dept
End Function
Please help, I have until about noon to figure this out.
There may some reasons:
1- Check if your page's viewstate is true.
2- Call your method after Page_Load event.
Where do you call the function?
Consider that you should call it after Page_Load event. Also your viewstate

ComboBox's Selected Value Changed On Lost Focus in VB.NET

I have a datagridview(dgv) with a DataGridViewComboBoxColumn(colLocation)
colLocation.AutoComplete = False
colLocation.HeaderText = "Stored to"
colLocation.DataSource = DB.getLocation()
colLocation.DisplayMember = "description"
colLocation.ValueMember = "id"
I added the colLocation to dgv.
"descirption" contains Unicode characters. I can see the comboBox correctly and choose the item.
The problem is when the comboBox lost the focus, the value is changed to first item of the comboBox.
Any suggestion?
Updated:
I found out that the ComboBox doesn't change the data when the DisplayMember is in English characters.
It changes only when the DisplayMember is in Unicode chracter. Any idea for how could solve this? – tunwn 0 secs ago
Your .aspx page should have something like so:
<asp:DropDownList Width="90px" ID="ddlExpenseTypes" OnSelectedIndexChanged="ddlExpenseTypes_SelectedIndexChanged" DataSource='<%# GetExpenseTypes() %>' SelectedValue='<%# Bind("ExpenseReasonID") %>' DataTextField="ExpenseReasonID" DataValueField="ExpenseReasonID" AutoPostBack="true" runat="server" ></asp:DropDownList>
That is you need a functional call for index changed. A function call for filling the drop down ist (DataSource) and a function call to set the SelectedValue of the drop down list.
Is this DataGridView databound? You haven't specified a value for DataPropertyName, so there's nothing for colLocation.ValueMember's ID selection to bind to.