|
There's no SelectedItem property ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Yes, I tried SelectedIndex property...but its doing the same thing.
May be I'm missing something or trying the wrong way. I tried this:
<br />
for (n = 0; n < cblRole.Items.Count; n++)<br />
{<br />
if (n == cblRole.SelectedIndex)<br />
arr[n] = 1;<br />
else<br />
arr[n] = 0;<br />
}<br />
|
|
|
|
|
Gosh - why not just set the selected index to 1 ? What happens when you debug it ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Sorry, may be I was not able to explain to you clearly.
I'm not clear why you said to set SlectedIndex to 1. What do I achieve by doing that?
These are a group of checkboxes and by using the loop, I wanted to identify the ones selected by storing 1 in the array, that I intended to use later.
Anyway, my problem is with selection/deselection. when a checkbox is clicked, how do I know it is selected or deselected (because I can't use the sender).
Thanks.
|
|
|
|
|
The CheckBoxList control returns only the first SelectedIndex. And since it is not an Array you must
check all Items.
foreach (ListItem item in cblRole.Items)
{
if (item.Checked)
{
}
}
|
|
|
|
|
Thanks digimanus and Christian.
I definitely tried this. What's happening is - the checkboxes are checked depending on values in a database table. When they make a new selection, it's suppossed to save the change in the database - then reflect the change in the checkboxes. My code works one way. If they make a new selection, it shows the checkbox as selected. If they deselect one, it doesn't work. It keeps the box as selected. So, I was thinking - it's a problem with the selection/desection.
But now feels like It's something else.
I'll review my code and come back.
Thanks again.
|
|
|
|
|
I have a CustomValidator control which is declared like this:
<br />
<asp:CustomValidator ID="m_DelayCodeValidator" runat="server"<br />
ControlToValidate="m_DelayCode" Text="*" ErrorMessage="Delay code"<br />
EnableClientScript="true"<br />
ClientValidationFunction="m_DelayCode_Validate" <br />
OnServerValidate="m_DelayCode_Validate" /><br />
I have a ValidationSummary control on the page as well. But when I try and submit the form the error message from my custom validator isn't listed with the other error messages in the ValidationSummary. The custom validation script isn't being called either - the script is only called when the value of ControlToValidate changes. I need the script called on submit as well like the other validators are.
ValidationSummary:
<asp:ValidationSummary ID="validationSummary" runat="server" DisplayMode="BulletList"<br />
HeaderText="Please enter the required values:" /><br />
ClientValidationFunction:
function m_DelayCode_Validate(sender, args)<br />
{<br />
if(m_DowntimeCode.options[m_DowntimeCode.selectedIndex].text != "Opportunity Maintenance")<br />
{<br />
args.IsValid = true;<br />
return;<br />
}<br />
<br />
if(args.Value == "" || args.Value == null || args.Value == undefined)<br />
args.IsValid = false;<br />
else<br />
args.IsValid = true;<br />
}<br />
|
|
|
|
|
I found the best thing is to dig in to the js that ASP.NET generates, and to write my own method that duplicates their calls but adds my own, if I want that degree of control.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Thanks for your suggestion. It led me to find a property I hadn't noticed as part of the CustomValidator control - ValidateEmptyText. Setting it to true fixes the problem for me. I guess I neglected to mention that the value of the default option was an empty string. I appreciate the help.
|
|
|
|
|
Glad to help
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Hi, I have the following code that is giving me this error:
An object reference is required for the non-static field, method, or property 'wwwroot_Admin_EditPuppies.PedDetailsView'
Here is the code in question:
<asp:Substitution ID="Substitution1" runat="server" MethodName="GetFilename"; />
and the script:
<script language="C#" runat="server">
static string GetFilename(HttpContext context)
{
int Record = (int)PedDetailsView.SelectedValue;
string file = DetailsView1.Rows[Record].Cells[8].Text.ToString();
Response.WriteFile(file);
}
</script>
Can someone PLEASE HELP me??? I have been trying forever to get this to work!!
|
|
|
|
|
Did you try google, or perhaps one of your C# references ? The error means what it says. You make a method static, and it cannot access instance variables. Why do you have static ? Remove it and it will build.
I NEVER put code in the aspx, that's just ugly and hard to read.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Hi, yes, I have literally spent hours combing through google searches and multiple forums, as well as all the C# books I have...I tried to take out the static, but it still gives the same error. As far as putting the code in the code behind file, I agree with you! However, every single instance I've found online put the Method for the Substitution in a <script> tag...the one time I did try to put the function in the code behind, I got an error that said it couldn't find the function.
Due to this, I have deduced that the method MUST be static when applied to a substitution control. I am very frustrated, and I really need some help on this issue. Thanks so much for your quick reply!
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">familyof7 wrote:</div>I got an error that said it couldn't find the function.</blockquote>
This would happen if you made it private. Make it public and I don't see how it could not be visible. Even protected would work, I think. It's not really going to change for the compiler that it's in the code behind.
I can't see any reason for it to need to be static. If it does, tho, the object that raised the event is the sender parameter, so cast that instead of grabbing it by name. ( oops, that doesn't work, sorry. It's not an event, and you are not accessing the control itself. I wish I could see the original post when I reply.... )
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
"The callback method that you specify must be a static method on the page or user control that contains the Substitution control."
Well, it looks like it does have to be static, which probably means you can't use it to do what you're trying to do. Unless your page will only ever have one user at a time, otherwise, I see no way out of it.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Yeah, I was thinking that too...could i use an iframe to display the excel file? I still have to get the filename from the database...let me try it this way and hopefully I'll get it working...
|
|
|
|
|
yeah, that would work, I think.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Me again...I've implemented the iframe control, now I'm getting the following error from the browser:
) expected.
Here's the tag:
Am I missing something?
|
|
|
|
|
I think you want = instead of #.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I use this code to save name of a picture in a table in database.file uploaded on a server but the name of that picture don't save on a database.
please help me.
protected void uploade_Click(object sender, EventArgs e)<br />
{<br />
if (uploadetest.HasFile == false)<br />
{<br />
uploadedetail.Text = "plese select youre file";<br />
}<br />
else<br />
{<br />
string filepath = Server.MapPath("~/pic/" + uploadetest.FileName);<br />
uploadetest.SaveAs(filepath);<br />
string FileName = string.Empty;<br />
FileName = uploadetest.PostedFile.FileName.Substring(uploadetest.PostedFile.FileName.LastIndexOf('\\'));<br />
<br />
<br />
string insertsql="INSERT INTO stt (picture) VALUES (@FileName)";<br />
SqlConnection con = new SqlConnection(connectionString);<br />
SqlCommand cmd = new SqlCommand(insertsql, con);<br />
con.Open();<br />
cmd.CommandText = insertsql;<br />
con.Close();<br />
<br />
}<br />
}
|
|
|
|
|
bbc_sh wrote: string FileName = string.Empty;
Why, when you're about to reset it ?
bbc_sh wrote: uploadetest.PostedFile.FileName.Substring(uploadetest.PostedFile.FileName.LastIndexOf('\\'));
Use Path.GetFileName for this
bbc_sh wrote: string insertsql="INSERT INTO stt (picture) VALUES (@FileName)";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(insertsql, con);
con.Open();
cmd.CommandText = insertsql;
con.Close();
you create a paraterised query, but never add your parameter value. Where did you think that the FileName string got passed to the SQL ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Also, your command is never actually executed against the database. You need to change this:
con.Open();<br />
cmd.CommandText = insertsql;<br />
con.Close();<br />
to this:
con.Open();<br />
cmd.CommandText = insertsql;<br />
cmd.ExecuteNonQuery();
con.Close();<br />
Also, as Christian mentioned, you need to set the parameter value:
<br />
cmd.Parameters.Add("@FileName", DbType.Varchar, 500);<br />
cmd.Parameters["@FileName"].Value = FileName;
|
|
|
|
|
I have the following templatefield in my gridview.
I wanted to show the value from my datasource in it but it doesnt show up, it shows error message:
Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ListItem does not have a DataBinding event.
<asp:templatefield headertext="Activity Order" xmlns:asp="#unknown">
<itemtemplate>
<asp:dropdownlist id="ddorder" runat="server" datasourceid="SqlDataSource1">
<asp:listitem text="<%# Eval(" order")="" %>"="" value="<%# Eval(">
is there a way to show values in a dropdownlist?
thanks
|
|
|
|
|
Yes. However, not the way you're doing it. I think you need to use the itemdatabound event, find your control and bind it to a source there.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
If I have got my datasource set in my aspx page how do I set a value selected from that query to my dropdown
i have this
DropDownList dd = ((DropDownList)row.FindControl("ddorder"));
dd.DataValueField =
thats in my databound event but how do I set it to the field from the query. I'm not sure of the syntax.
In my aspx the other fields in the gridview are just set like normal bound fields
|
|
|
|