How can I set a label form database [closed] - asp.net

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to set a label with something out a database.
This is my query:
string strQuery = "Select * FROM Contacts Where User='" + strSelectedUser + "'";
SqlCommand command = new SqlCommand(strQuery, Global.myConn);
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(Global.ds, "Tabel");
Now I want to set a label
lblContact.Text=......[column database = name]....?
How do I do that?

Please use blow code to set label value from database.
First check that your query is retuning value then assign the value to label text
if(Global.ds.Tables["Tabel"].Row.Count>0)
{
lblContact.Text=Global.ds.Tables["Tabel"].Rows[0]["Colomn_Name"].toString();
}

Related

need to show asp.net message box (after validating data with database) Not immediately after button click [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to show asp.net message box with yes and no (after validating the data with database)
My Requirement is
Before inserting of any data into Database(I need to check the data is present is DB on that data)
If data is present I need to show message box stating that data exists on the same day ? Are you sure want to save the data or cancel the
Not immediately after button click
please help me
Do you need help with validation?
Otherwise you just need to
If(isValid){
//Show MessageBox
}
Check validation first, if its valid show the messagebox.
On btn save_click.first check that data exists or not if exists then show message else save it. You can do like this:
SqlConnection con = new SqlConnection("Connectionstring");
con.Open();
string query = "Select count(*) from AD_Organisation where OrgName=#a";
SqlCommand cmd1 = new SqlCommand(query, con);
cmd1.Parameters.AddWithValue("#a", txtorgname.Text.ToString());
int count = Convert.ToInt32(cmd1.ExecuteScalar());
con.Close();
if (count > 0)
{
//show message that the data already exists
//call javascript
}
else
{
//insert command
}
For popup message you can use the javascript :
<script language="javascript" type="text/javascript">
function showalert() {
alert('Data already exists');
return false;
}
</script>
For calling the javascript message use
ScriptManager.RegisterStartupScript(this, GetType(), "display", "showalert('msg');", true);

how to get cell value Datagrid EasyUI PHP clicked [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
can somebody help me how to get selected cell value when I click cell of Datagrid ? wondering I have datagrid with 5 fields and many rows, but I want to get cell value from datagrid which I clicked the row. Thanks advance.
If you need get row's value use this :
var row = $('#datagrid').datagrid('getSelected');
If you need get cell's value use this :
$('#datagrid').datagrid({'onClickCell': function (index, field, value) {
.... your code ...
}});
first you need to set datagrid property with onClickRow: onClickRow,
and then you can add this function
function onClickRow(index){
var tr = $(this).closest('tr.datagrid-row');
var idx = parseInt(tr.attr('datagrid-row-index'));
var ed = $("#dg").datagrid("getEditor", {index:editIndex, field:'myfield'});
var value = $(ed.target).val();
}
value variable will fill with the value from myfield when the row is click
Hope this can help you

How to give resolution for looking server folders? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
In my web application users need to chose folder with special file. But they don't see paths on server. How can I open server folders for viewing?
On local machine i look all directories fine:
On server like this:
call the TreeADirectory with a valid server path and you will have you tree rendered :)
private void TreeADirectory(TreeView treeView, string pathToList)
{
treeView.Nodes.Clear();
var rootInfo = new DirectoryInfo(pathToList);
var node = CreateDirNodes(rootInfo);
treeView.Nodes.Add(node);
}
private static TreeNode CreateDirNodes(DirectoryInfo directoryInfo)
{
var directoryNode = new TreeNode(directoryInfo.Name);
var dirs = directoryInfo.GetDirectories()
foreach (var directory in dirs)
{
directoryNode.Nodes.Add(CreateDirectoryNode(directory));
}
//only if you need to show files
var files = directoryInfo.GetFiles()
foreach (var file in files )
{
directoryNode.Nodes.Add(new TreeNode(file.Name));
}
return directoryNode;
}

How can i publish Page using TOM.net api? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Is it possible to publish a Page by using Tom.net API in SDL Tridion 2011?
As Nuno mentioned, use PublishEngine.Publish and refer the syntax and example
Syntax:
PublishEngine.Publish(
new IdentifiableObject[] { linkedComponent },
engine.PublishingContext.PublishInstruction,
new List() { engine.PublishingContext.PublicationTarget });
Do something like this:-
private void Publish(IdentifiableObject item, PublicationTarget publicationTarget, bool rollBackOnFailure, bool includeComponentLinks)
{
IEnumerable<IdentifiableObject> items = new List<IdentifiableObject>() { item };
IEnumerable<PublicationTarget> targets = new List<PublicationTarget>() { publicationTarget };
PublishInstruction instruction = new PublishInstruction(item.Session)
{
DeployAt = DateTime.Now,
RenderInstruction = new RenderInstruction(item.Session)
{
RenderMode = RenderMode.Publish
},
ResolveInstruction = new ResolveInstruction(item.Session)
{
IncludeComponentLinks = includeComponentLinks
},
RollbackOnFailure = rollBackOnFailure,
StartAt = DateTime.MinValue
};
PublishEngine.Publish(items, instruction, targets);
}
**Contents is copied from How to Publish Stuff Programmatically blog
Use PublishEngine.Publish, follow Intellisense from there. You'll need to provide Render and Resolve instructions, as well as the usual details like Target, start date/time, etc.
The documentation has samples, various blogs have samples, and Visual Studio should help you find what you need.

how to open a message box [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
i m writing the code:
string query = "Select * from AdminLogin where username='" + name +
"' and password='" + password + "'";
DataSet ds = BusinessLogic.returnDataSet(query);
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr[0].ToString() == name && dr[1].ToString() == password)
{
Response.Redirect("~/Home.aspx");
}
else
{
//Here I want to write the code that will open a message box
//that will tell to user that username and password does not match.
}
}
By message box I'm assuming you mean a javascript alert. I'm not a big fan of posting back with javascript functions. I think its messy, and that javascript should only be used when dealing with client-side actions.
I would actually recommend to use a placeholder and a literal control for this. You could have the following in your webform:
<asp:placeholder id="phLoginFailed" runat="server" visible="false">
<div class="loginfailed">
Login failed
</div>
</asp:placeholder>
This placeholder could be styled like a popup, or displayed within your page using CSS.
Then change your C# to:
else
{
phLoginFailed.Visible = true;
}
Also, its worth mentioning, your SQL query is prone to SQL Injection. You should use parameterised queries.
And you should encrypt passwords when storing them in the database for security purposes.
This is not as easy as it sounds. Basically, you have two options:
Send some JavaScript to the client (for example, using RegisterClientScriptBlock) which calls the JavaScript alert(...); method.
Alternatively, use an ASP.NET component that "looks like" a popup. One example is the ModalPopup component in the ASP.NET Ajax Control Toolkit.
ClientScript.RegisterClientScriptBlock(Page.GetType(),"key", "alert('Wrong username or password')", true);
or if it is used outside page scope
then
Page page = (HttpContext.Current.Handler as Page);
if (page!=null)
{
page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "key", "alert('Wrong username or password')", true);
}
just write this line where you want o show message
this.Page.RegisterClientScriptBlock(Page.GetType(),"key", "alert('Wrong username or password')",true);
Edited code
if (dr[0].ToString() == name && dr[1].ToString() == password)
{
Response.Redirect("~/Home.aspx");
}
else
{
this.Page.RegisterClientScriptBlock(Page.GetType(),"key", "alert('Wrong username or password')",true);
//Here I want to write the code that will open a message box
//that will tell to user that username and password does not match.
}

Resources