|
Sir,
I am developing an application in ASP.NET.It's using a MS-Access database and I am listing ten Emp_IDs from the table Employee to DropdownList.I want to select particular Emp_Name from Employee table on click on DropdownList. Pleas help me to solve this problem.
Praveen.K
System Engineer
Graviton Technologies Pvt.Ltd
|
|
|
|
|
What do u want to do??On select index change of combo u want to display the selected employee details or something else??
|
|
|
|
|
Make the auto post back of drop downlist true and use dropdownlist selectedItem prepertyn in the dropdownlist_selectedIndexchanged function ?
|
|
|
|
|
Your probelm is not clear when and why you want to select employee , please explain your question.
If you are filling dropdownlist use its property autopsotback=true which is false by default.
Now use SelectedIndexChange event of your dropdownlist.
if you have fetch data from database on the basis of rowselected in the dropdowlist.
You have to keep in mind that weahter you are using DataTexFiled property and DataValuefield property of the Dropdownlist
if you are using these two then you can query your database like this
sql="select * from tbl where field="+ dropdownlist.selectedValue or
sql="select * from tbl where field="+ dropdownlist.selectedItem
if you are not using these two properties then
you can use
sql="select * from tbl where field="+ dropdownlist.Text
Hope it will help you .
Naveed Kamboh
|
|
|
|
|
By using SQLString = "SELECT Name FROM test WHERE ID = +DropDownList1.SelectedValue"
I got the selected item from dropdown list.Now how can i place the out put of the query in a DataGrid? i want the syntax or coding?
-- modified at 23:32 Thursday 1st February, 2007
Praveen.K
System Engineer
Graviton Technologies Pvt.Ltd
|
|
|
|
|
I want a column in my datagrid to be edited by a drop down list.
I've put the dropdown list in the edititem template.
The contents of the DropDown is sourced from an SQLDataSource
And the data bindings set up a two way binding to the "Record" field.
I have added this update control parameter
Where:
"Recorded" is the Parameter name.
"gvOutgoing" is the GridView
"Selected Value" is the feild i want from the dropdownlist
<br />
<UpdateParameters><br />
<asp:ControlParameter name="Recorded" controlid="gvOutgoing" propertyname="SelectedValue"/><br />
<UpdateParameters><br />
This generates no errors except it passes a NULL value to @Recorded
Now I originaly thought i should put "ddlRecorded" (the drop down list) in the "controlid" as thats what i want the actaul value of.
except it kept giving me this error:
Could not find control "ddlRecorded" in ControlParamert "Recorded".<br />
<br />
Any adivce?<br />
<br />
Cheers
|
|
|
|
|
Because you want to get the value from the dropdownlist then the ControlID should point to this control, not the GridView. However, the dropdownlist is contained inside the GridView, therefore the value of the ControlID will be the uniqueID of the dropdownlist including the id of the containers. So it should be something like gvOutgoing$ctl02$ddlRecorded (or you can replace the $ with the : ). There's one more important thing is that the uniqueId of the dropdownlist varies from row to row, so you'll have to update the ControlID dynamically according to which row is being edited.
|
|
|
|
|
THANK YOU SO MUCH!
I've been pulling my hair out all day over that
Could you point me to some reference about this so I could understand why it works and possibly find a way to generate that automaticly?
Thanks again
|
|
|
|
|
|
Hi Everybody
I got a TextBox under a Button on the form, talking ID number from the TextBox for creating a Report. If I change the TextBox value then reportviewer cant change the Report it remain same. I put some ToggleBreak point to see the code is working or not, code change the value and working but cant show it on ReportViewer.
FirstTime: TextBOx(CustomerID) = 10, Getting all details about customer whose ID 10
SecondTime: TextBox(CustomerID) = 20, cant getting the Report about CustomerID 20 , its remain same.
I need your help
Thanks
Sarfarj Ahmed
|
|
|
|
|
HI
i think the object in which you are getting the report is not refreshing can you post the code where you are geting report and displaying it ?
|
|
|
|
|
Hi Sandeep
Please check the code and let me know
Thanks
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
Partial Class Member_Members
Inherits System.Web.UI.Page
Protected Sub btnSearchMember_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchMember.Click
Dim con As DataAccess = New DataAccess()
Dim conLessons As SqlConnection = con.SQLConnnect()
Dim cmd As SqlCommand = New SqlCommand()
Dim _DataReader As SqlDataReader
Dim _DataSet As DataSet = New DataSetMember()
Dim _ReportDataSource As ReportDataSource = New ReportDataSource()
Try
conLessons.Open()
cmd.CommandType = CommandType.Text
cmd.Connection = conLessons
cmd.CommandText = "Select AutoID, ForeName, SurName From Members Where AutoID=" & TextBox1.Text & ""
_DataReader = cmd.ExecuteReader()
_DataSet.Tables(0).Load(_DataReader)
_DataReader.Close()
conLessons.Close()
ReportViewerMembers.LocalReport.ReportPath = Server.MapPath("~/Member/ReportMembers.rdlc")
_ReportDataSource.Name = "DataSetMember_Members"
_ReportDataSource.Value = _DataSet.Tables(0)
ReportViewerMembers.LocalReport.DataSources.Add(_ReportDataSource)
ReportViewerMembers.LocalReport.Refresh()
Catch ex As Exception
If conLessons.State = ConnectionState.Open Then
conLessons.Close()
End If
End Try
End Sub
End Class
Sarfarj Ahmed
|
|
|
|
|
Hi Sarfaraz
please debug it and put a beak point in _DataSet.Tables(0).Load(_DataReader)
and see the latest data is there in the dataset also check your query and value in Textbox1.text ....... as it is in VB i am not getting
|
|
|
|
|
Hi Sandeep
I did it, I can see the latest data inside the code but not on the report viewer
thanks
Sarfarj Ahmed
|
|
|
|
|
hi,
is there any reference or code snippet for the follwing:
Required data is present in an excel sheet, and this data is supposed to be displayed in a datagrid.
Secondly, what if we just want to display only few records of an excel sheet on to the datagrid
c# is the language.
Thanks!
Gautham
|
|
|
|
|
.NET Classes used :
System.Data.DataSet
System.Data.OleDb.OleDbDataAdapter
System.Data.OleDb.
System.IO.StringWriter
System.Web.UI.HtmlTextWriter
This application uses a FileField (UploadFile)(HTML control) , One label (lblMessage), Button (btnSubmit), Button (btnExportToExcel), DataGrid (DataGrid1), This also explains how to upload a file.
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Code :
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String
If Not (UploadFile.PostedFile Is Nothing) Then
strFileNamePath = UploadFile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
Dim paths = Server.MapPath("/excelreading/")
paths = paths & "Excel/"
'If File.Exists(paths & strFileNameOnly) Then
'lblMessage.Text = "Image of Similar name already Exist,Choose other name"
'Else
If UploadFile.PostedFile.ContentLength > 40000 Then
lblMessage.Text = "The Size of file is greater than 4 MB"
ElseIf strFileNameOnly = "" Then
Exit Sub
Else
strFileNameOnly = Session("AdminID") & "-" & Session("Acountry") & "-" & Format(Date.Today, "mm-dd-yyyy").Replace("/", "-") & ".xls"
UploadFile.PostedFile.SaveAs(paths & strFileNameOnly)
lblMessage.Text = "File Upload Success."
Session("Img") = strFileNameOnly
End If
End If
'End If
Dim myDataset As New DataSet()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("/excelreading/") & "excel/" & strFileNameOnly & ";" & _
"Extended Properties=Excel 8.0;"
''You must use the $ after the object you reference in the spreadsheet
Dim myData As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
myData.TableMappings.Add("Table", "ExcelTest")
myData.Fill(myDataset)
DataGrid1.DataSource = myDataset.Tables(0).DefaultView
DataGrid1.DataBind()
End Sub
Private Sub btnExportToExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
DataGrid1.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
lblMessage.Text = "For any more information , feel free to contact ...!!!"
End Sub
ref : http://www.dotnetspider.com/kb/Article361.aspx
Parwej Back...............DON of Developer.......
Parwej Ahamad
g_parwez@rediffmail.com
|
|
|
|
|
Search for macro in Excel easy and faster
|
|
|
|
|
could you throw more light on this!!!
Gautham
|
|
|
|
|
Ya Macro is in VB and is Excel Language it is always better to write Macro than Using Excel Object You will find on net search by 'reading data Excel macro'
|
|
|
|
|
OPen the Excel sheet GO to tools macro and Visual basic Editor find examples from net how to get data from Excel using macro
|
|
|
|
|
/*
This is my oracle function
*/
create or replace function EngUnitConvert(sSrcEng in varchar2, sDstEng in varchar2)
return number
is
AtLeastLostOneCoefficient exception;
vSrcEng Number;
vDstEng Number;
vValue Number;
BEGIN
begin
-- Get source
SELECT Mult_Fctr
INTO vSrcEng
From ip_eng_unit t
WHERE t.units = UPPER(sSrcEng);
dbms_output.put_line('Source Coefficient :' || to_char(vSrcEng));
-- Get destination
SELECT Mult_Fctr
INTO vDstEng
From ip_eng_unit t
WHERE t.units = UPPER(sDstEng);
dbms_output.put_line('Destination Coefficient :' || to_char(vDstEng));
if ((vSrcEng is null) or (vDstEng is null)) then
dbms_output.put_line('At Least Lost One Coefficient!');
raise AtLeastLostOneCoefficient;
else
vValue := vDstEng / vSrcEng;
dbms_output.put_line('Result Coefficient :' || to_char(vValue));
end if;
dbms_output.put_line('Finished!');
return vValue;
end;
exception
when AtLeastLostOneCoefficient
then null;
WHEN OTHERS THEN NULL;
END;
/*
This is my OleDbCommand call,but it failed
*/
// here OleDbConnecton have opened
OleDbCommand sqlcmd = new OleDbCommand();
sqlcmd.CommandText = "unitconvert";
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Connection = olecn;// olecn -- OleDbConnecton
OleDbParameter ps = new OleDbParameter("s_from_eng",System.Data.OleDb.OleDbType.VarChar,32);
ps.Direction = System.Data.ParameterDirection.Input;
ps.Value = sFromUnit;
OleDbParameter pd = new OleDbParameter("s_from_eng",System.Data.OleDb.OleDbType.VarChar,32);
pd.Direction = System.Data.ParameterDirection.Input;
pd.Value = sToUnit;
OleDbParameter pr = new OleDbParameter("vvalue",System.Data.OleDb.OleDbType.Numeric,16);
pr.Direction = System.Data.ParameterDirection.ReturnValue;
sqlcmd.Parameters.Add(ps);
sqlcmd.Parameters.Add(pd);
sqlcmd.Parameters.Add(pr);
sqlcmd.ExecuteNonQuery();
string sValue = sqlcmd.Parameters["vValue"].Value.ToString();
/*
The error messages is:
*/
ORA-06550: line 1, column 7:\nPLS-00201: identifier 'UNITCONVERT' must be declared\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored
/*
Here is OracleDbCommand call,it success
*/
OracleConnection orcn=new OracleConnection("user id=totalplant;data source=totalplant;password=totalplant");
OracleCommand cmd=new OracleCommand("unitconvert",orcn);
cmd.CommandType=CommandType.StoredProcedure;
OracleParameter p1=new OracleParameter("s_from_eng",OracleType.VarChar,32);
p1.Direction=System.Data.ParameterDirection.Input;
p1.Value= "g";
OracleParameter p2=new OracleParameter("s_to_eng",OracleType.VarChar,32);
p2.Direction=System.Data.ParameterDirection.Input;
p2.Value= "tonne";
OracleParameter p3=new OracleParameter("vValue",OracleType.Number,100);
p3.Direction=System.Data.ParameterDirection.ReturnValue;
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
orcn.Open();
cmd.ExecuteNonQuery();
orcn.Close();
|
|
|
|
|
Hi,
I have created user control called UserCtrl.ascs in my solution which includes two textboxes in that usercontrol and and also i have added the following code in .ascx.cs page.
public string pUser
{
get
{
return TextBox1.Text.Trim;
}
set
{
TextBox1.Text = value;
}
}
public string pPass
{
get
{
return TextBox2.Text.Trim;
}
set
{
TextBox2.Text = value;
}
I added that user control to my aspx page. Please tell me how to use that textboxes inside aspx.cs page.
Thanks in Advance,
Regards,
Prya
|
|
|
|
|
create object of that user control class, and and set the value of properties...
|
|
|
|
|
this.UserCtrl.TextBox1.value this way
|
|
|
|
|
As blue_arc said, you use user control from page codebehind same way as if it was standard ASP.NET web control.
Assuming you have in your aspx file:
<uc:userCtrl runat="server" id="myCtrl"/>
in codebehind do:
string password = myCtrl.pPass;
Is it clear?
You should not try to access textboxes directly, as it goes against encapsulation principle (hence I downvoted guy above me :P).
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|