|
Hi experts,
When I execute the following code,
<asp:CheckBoxList ID="ckRequestReview" runat="server" CssClass="cb" Style="border-width: 0;" RepeatDirection="horizontal" RepeatColumns="4" RepeatLayout="Table">
<asp:ListItem>Step One</asp:ListItem>
<asp:ListItem>Step Two</asp:ListItem>
<asp:ListItem>Step Three</asp:ListItem>
</asp:CheckBoxList>
Dim items As String = String.Empty
If items = "Step One" Then
mypreferredChange = txtTitleChange.Text
ElseIf items = "Step Two" Then
mypreferredChange = "txtPayGradeChange"
ElseIf items = "Step Three" Then
mypreferredChange = "txtClassSpecChange"
Else
cmd.Parameters.Add(New SqlParameter("@RequestedChange", mypreferredChange))
Dim result As Integer = cmd.ExecuteNonQuery()
End If
The checkbox values are stored in one database column name called ChValues.
If a user checks one item, that one item is stored in that fieldname.
If user checks all three, all three are stored in that one fieldname, separated by comma.
In our situation, as in the example above, we have three items on the checkboxlist.
We would like to store the value of each checkboxlist into a separate fieldname.
Is this possible?
The idea is that when we query the db to retrieve these values, we would like each to have its own checkmark.
Thanks a lot in advance
|
|
|
|
|
Yes.
You would create your table with individual columns for each checkbox. You could make each column a char(1) and store Y or N.
|
|
|
|
|
Thank you for the prompt response.
This is what I have in mind.
Let's say I have three columns called simply, Column1, Column2, Column3
And I want to store the following values for them.
Column1 one gets Step One as value
Column2 gets Step Two as value
Column3 gets Step Three value stored in it.
Now, when I query the db to select all three columns, I would like each column preceded by checkmark like:
[]Step One []Step Two []Step Three
Note, I am using [] to represent checkmark.
How do I do this?
|
|
|
|
|
Create three columns (Step1 , Step2 and Step3 ) using the bit type. (This corresponds to the Boolean type in .NET.)
Find the items in the CheckBoxList and add them as separate parameters:
Dim item As ListBoxItem = ckRequestReview.Items.FindByText("Step One")
cmd.Parameters.AddWithValue("@Step1", item IsNot Nothing AndAlso item.Selected)
item = ckRequestReview.Items.FindByText("Step Two")
cmd.Parameters.AddWithValue("@Step2", item IsNot Nothing AndAlso item.Selected)
item = ckRequestReview.Items.FindByText("Step Three")
cmd.Parameters.AddWithValue("@Step3", item IsNot Nothing AndAlso item.Selected)
When you query the data, just select the three columns. The value of each column will be True if the item was selected, and False otherwise.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Awesome!
Thanks so much for your continued support Richard.
|
|
|
|
|
Yes, you can put you CheckBoxList Value into DB.
|
|
|
|
|
i Want to display an multiple images using datalist
asp Code:
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
Width="100%" BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px">
<ItemTemplate>
<asp:Label ID="lblsStatus" runat="server"></asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("imgname1") %>' Font-Bold="True"
Font-Size="10pt" ForeColor="#336699" Width="100%" />
<br />
<asp:Image ID="imgsss" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top" />
</asp:DataList>
c#:
protected void Page_Load(object sender, EventArgs e)
{
FetchImage();
}
private object GetData(string query)
{
DataTable dt = new DataTable();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
return dt;
}
}
protected void FetchImage()
{
string id = "1";
imgss.Visible = id != "0";
if (id != "0")
{
byte[] bytes = (byte[])GetData("SELECT imgdata1 FROM Tbl_images WHERE id =" + id);
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
imgss.ImageUrl = "imgdata1:image/png;base64," + base64String;
}
}
|
|
|
|
|
You didn't told what the problem, but I can spot a syntax problem that fixing it may help you...
... = "imgdata1:image/png;base64,"...
It should be
... = "data:image/png;base64,"...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
error:
Unable to cast object of type 'System.Data.DataTable' to type 'System.Byte[]'.
|
|
|
|
|
And?
Are you really meant to convert the DataTable to byte array? Or by any chance you want to convert the field's content?
Change GetData so it will return only the data you need, something like this:
dt.Rows[0]["column-name-for-image-data"]
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
You are returning the wrong object type from your GetData method. A DataTable is not compatible with a Byte[] , so you cannot use a cast.
|
|
|
|
|
Two option for you .
1. Just Change "imgdata1" to "data" in you code .. for example
imgss.ImageUrl="data:image/png;base64," + base64String;
2. With the use of Handler file. (Do Google for it)
|
|
|
|
|
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Also, you won't have a control called imgss at the page level. The control is defined within a data-bound list; once the list is data-bound, there will be one copy of the control for each item in the list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
HI,
This the code:-
foreach(GridViewRow row in GridView1.Rows)
{
if(row.RowType==DataControlRowType.DataRow)
{
//code here
}
}
I didn't understand this line of code: if(row.RowType==DataControlRowType.DataRow)
Can anyone help???
|
|
|
|
|
the DataControlRowType can be the following:
DataRow
EmptyDataRow
Footer
Header
Pager
Separator
so if the row is a "DataRow" then it is a row with data
|
|
|
|
|
|
I am willing to embed live video into my asp.net+vb web page.
The input is from the camera and it is connected to the inbuilt DVR Card (in AGP slot in my PC)
i dont want to use the interface provided by the DVR firm. as they shows their names and menu
i want iyt to be embeded and futher i can change the layout etc.
|
|
|
|
|
Dear All!...
I am working in asp.Net with c# Language. I am using Date Time Picker with Text Box. If i am pick the Text Box date time picker is show in first time after Refresh the page date time picker is not shown again.(Note:I am using master page).
Following Script i am using in my page.
$(function () {
$(".date").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd M yy',
yearRange: "-100:+10"
});
});
Thanks for advance!....
|
|
|
|
|
Let me guess, there is something vitally important about your problem you have chosen not to tell us, such that you're using an updatepanel, or some other kind of ajax?
|
|
|
|
|
|
In Google Chrome, hit F12, go to Console tab, see if you have any JavaScript errors.
|
|
|
|
|
Currentlly i have started on gps tracking software and i have no idea about it. Plz help me on this. On gps device i set ip and port then after on particular time interval gps send the data on server. Please tell me how to capture this data. Its urgent for me please help.
|
|
|
|
|
Amitk765 wrote: and i have no idea about it So pick your favorite search engine and start looking for material for your subject...
As now you only have a - somewhat hidden - code request only...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
But, but it's urgent, don't ya see!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
How to drag cities into dropdownlist (city) from selected dropdownlist (state) of respected state.
E.g. In dropdownlist selected state is Maharashtra, so drag all respected state cities into dropdownlist (city).
|
|
|
|