|
In my page, I have a datatable with duplicate data and I use the following code to make distinct column values.
private ArrayList RemoveDuplicatePartNumbers(DataTable dtParts)
{
ArrayList lstparts = new ArrayList();
DataTable dt1 = new DataTable();
//Assigning the table to DataView, which will remove duplicates after sorting.
DataView dv = new DataView(dtParts);
dv.Sort = "PartNumber ASC";
string[] strcolumns = { "PartNumber" };
dt1 = dv.ToTable(true, strcolumns);
for (int i = 0; i <= dt1.Rows.Count - 1; i++)
{
lstparts.Add(System.Convert.ToString(dt1.Rows[i]["PartNumber"]));
}
return lstparts;
}
Now my question is, can I reduce the above coding lines to some extent by using DataView.Select property or in some other way? Any thoughts? Please help.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
Hi, you can fire a Linq query instead.
I have created a Datatable
public DataTable FunctionGetTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("PartNumber");
dt.Rows.Add("PartNumber1");
dt.Rows.Add("PartNumber5");
dt.Rows.Add("PartNumber6");
dt.Rows.Add("PartNumber3");
dt.Rows.Add("PartNumber3");
dt.Rows.Add("PartNumber6");
dt.Rows.Add("PartNumber3");
dt.Rows.Add("PartNumber5");
dt.Rows.Add("PartNumber5");
return dt;
}
My ArrayList function goes like this
private ArrayList RemoveDuplicatePartNumbers(DataTable dtParts)
{
ArrayList lstparts = new ArrayList();
var query = (from c in dtParts.AsEnumerable()
orderby c.Field<string>("PartNumber")
select c).Distinct(DataRowComparer.Default);
foreach (var d in query) lstparts.Add(d);
return lstparts;
}
Next call the function from any control's event(I have called from a button event)
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList RequiredList = new ArrayList();
RequiredList = RemoveDuplicatePartNumbers(FunctionGetTable());
}
Hope this helps
Niladri Biswas
modified on Wednesday, July 1, 2009 8:22 AM
|
|
|
|
|
Thanks a lot for your detailed reply. It worked!!! and I learned something about Link queries. Great Forum!!!
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
Hi..
I have hosted my Asp.net application on Godaddy shared hosting environment. Now I want to upload images to my hosting server by using my code. So I used file upload control to upload my files, when I am trying to upload file on to my web server every time it's prompting window for user name password of my domain .can anyone tell me how can I upload a file on to my shared hosting environment without prompting authentication window.
Thanks in advance.
bah10z
|
|
|
|
|
You need to have appropriate permissions to write(upload) a file on the server.
Read this [^]on MSDN to understand what all permission you would need.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
engbahramZarin wrote: when I am trying to upload file on to my web server every time it's prompting window for user name password of my domain .
Do you have the sufficient permission to upload the file ? is there any domain user name password you have for the hosting side?
|
|
|
|
|
I have four individual checkboxes in my form called as General, Direct, Indirect and Private. The issue is that when private is checked all others should be disabled and unchecked if checked. I have the following code for that:
if (PrivateCheckBox.Checked)
{
GeneralCheckBox.Checked = false;
GeneralCheckBox.Enabled = false;
IndirectCheckBox.Checked = false;
IndirectCheckBox.Enabled = false;
DirectCheckBox.Checked = false;
DirectCheckBox.Enabled = false;
}
else
{
GeneralCheckBox.Checked = true;
GeneralCheckBox.Enabled = true;
IndirectCheckBox.Checked = true;
IndirectCheckBox.Enabled = true;
DirectCheckBox.Checked = true;
DirectCheckBox.Enabled = true;
}
This serves the purpose but simply increases coding lines which I don't want. I can use the ternary operator, but only one operation can do with that, either checked or enabled. Can anybody have any idea how to achieve this with minimum line of code? I am not able to think of any other option.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
GeneralCheckBox.Checked = GeneralCheckBox.Enabled = !PrivateCheckBox.Checked;<br />
IndirectCheckBox.Checked = IndirectCheckBox.Enabled = !PrivateCheckBox.Checked;<br />
DirectCheckBox.Checked = DirectCheckBox.Enabled = !PrivateCheckBox.Checked;
only two letters away from being an asset
|
|
|
|
|
Add the check boxes (except private check box ) to a checkbox group. and use this code
foreach (CheckBox ch in CheckBoxList1.Items)
{
if(private.checked)
{
ch.Checked = false;
ch.Enabled = false;
}
else
{
ch.Checked = true;
ch.Enabled = true;
}
}
If you want to do similar kind of operation to a group of items then this is the standard way of doing that. Hope this help
|
|
|
|
|
foreach (control ctrl in page)
{
if(ctrl is checkbox)
{
((checkbox)(ctrl)).enabled = false;
((checkbox)(ctrl)).checked = flase;
}
}
|
|
|
|
|
This will not work, as it is giving the error as " foreach cannot operate on variables of type System.Web.UI.Page because System.Web.UI.Page does not contain a public definition for 'GetEnumerator'"
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
Hi All
i am assingning a dynamic value to image through hidden feild value and it is not working.
the tag is
<img src="<%hidden1.value%>" alt=""/>
this does not show any image and on checking the properties of image it says no URL defined
Thanks in advance!!!!!
|
|
|
|
|
<%=
you are missing "=" char
|
|
|
|
|
IT_Help wrote: the tag is
use
IT_Help wrote: this does not show any image and on checking the properties of image it says no URL defined
What is the hidden1.value returning, From Are you giving the path ??
|
|
|
|
|
Add this code in your aspx page.
<INPUT type="hidden" id="MyHiddenField" runat="server" value="http://tbn2.google.com/xy/ab.JPG">
<img runat="server" id="hiddenImg" alt="" />
and in code behind add this code
HtmlInputHidden hidden = (HtmlInputHidden)Page.FindControl
("MyHiddenField");
Img.Src = hidden.Value;
Hope this help.
|
|
|
|
|
how to check whether Nodes has ChildNodes or not, when i calling i nodes from database.....will it be checked on any NodeExpanded event and if yes give me some guidance
|
|
|
|
|
KhandelwalA wrote: how to check whether Nodes has ChildNodes or not, when i calling i nodes from database.....will it be checked on any NodeExpanded event
I didn't understand your problem. Can you please explain clearly ?
Thank you !
|
|
|
|
|
Hello Friends,
I've two dropdownlist(ddlCountry,ddlState). Onchange event of CountryDropdown(ddlCountry) StateNames are displayed into StateName dropdown using javascript. And it's working fine but prooblem is if i print the value of selected StateName on a button click at code-behind i got an error <b>Object reference set to an instance of an object</b>. So can anybody let me know what should i do know
|
|
|
|
|
your question is clear... Plzzzz send the code upto which level you have tried and the line where u r getting that error...
|
|
|
|
|
This is my javascript function
function myFunc()
{
if(document.getElementById("ddlCountry").value=="India")
{
//Remove Existing Values
var e=document.getElementById("ddlState");
while(e.firstChild)
{
e.removeChild(e.firstChild);
}
var myArray=new Array(2);
myArray[0]="Delhi";
myArray[1]="Mumbai";
for(var i=0;i<myArray.length;i++)
{
//Option(Text,Value)
e.options[i]=new Option(myArray[i]);
}
}
else if(document.getElementById("ddlCountry").value=="America")
{
//Remove Existing Values
var e=document.getElementById("ddlState");
while(e.firstChild)
{
e.removeChild(e.firstChild);
}
var myArray=new Array(2);
myArray[0]="Washington";
myArray[1]="LA";
for(var i=0;i<myArray.length;i++)
{
//Option(Text,Value)
e.options[i]=new Option(myArray[i]);
}
}
}
This is my .aspx code
<asp:DropDownList ID="ddlCountry" runat="server" onchange="myFunc(this)">
<asp:ListItem Text="Select Country" Value="Select Country"></asp:ListItem>
<asp:ListItem Text="India" Value="India"></asp:ListItem>
<asp:ListItem Text="America" Value="America"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlState" runat="server">
</asp:DropDownList>
This is my Code-Behind(on button click event) code
string name = ddlCountry.SelectedItem.Text+","+ddlState.SelectedItem.Text;
Label1.Text = name.ToString();
And ddlState.SelectedItem.Text getting null that's why that's throwing error
|
|
|
|
|
i too got the same error from your code... The problem is due to postback. The ddlCountry value is maintained but ddlState value is not maintained. So, the error appears. Try to maintain the value for the ddlState too...
|
|
|
|
|
Save the state of drop down list get value from request.form or query string do not fill all entry every time because if you did so every time new values is filled and state can not be maintained you can try one more option before submitting the form save the value into hidden variable by using java script and then get values from request object not from drop down because it lost their value when it fill again
|
|
|
|
|
hi
In my asp.net application i m updating a table.After that i m using those values
now i want to reverse those changes .i hav no idea how to do it
help me its urgent
|
|
|
|
|
you can use transaction (commit and rollback) option.
|
|
|
|
|