|
|
I have a dynamically created grid view with a nested child grid view. On edit,I wanted to have different controls based on column data type so when I create template fields dynamically, I create user controls and add to grid view in edit Item template. grid view works fine with most of the data but with some special data when I want to edit a row, nothing happens and none of the buttons on the page works.
I used firebug to find out the error. I got the "Failed to load viewstate" error. Nothing is different with the other data that works fine but I don't know why some times edit doesn't work. I found out that if I remove a row from grid view edit works correctly!if the grid view row count is 16, I remove a row so with row count=15 it works. even when row count is 6 it works with 5. but as I said there isn't a rule and most of the time it works fine with any row count. Any one has idea what to do? Thank you.
|
|
|
|
|
could anyone please tell me how to implement radiobuttonlist with accordion style
|
|
|
|
|
Radiobuttonlist - consist of list of radiobuttons which can be used without creating a group name.
It may have many radiobutton but still it is a single control.so you cannot split it.
Try with RadioButton control
To learn all there is to know. I know I'll be disappointed one day, but I've made a good start, and the eventual disappointment is likely to be brief.
-Roger Wright
|
|
|
|
|
Dear All,
How can insert a data into SQL(MS SQL 2008 ) data base with apostrophe.
Please provide sample code to insert with a stored procedure from C#.Including all DB connectivity
Thanks,
Praveen Machat
|
|
|
|
|
|
You are creating the SQL query by concatenating strings, aren't you? That's very bad practise, and beyond the trouble with the apostrophes (and dates, and non-ASCII-characters, and ...), it invites SQL Injection attacks. Use a Parameterized Query instead.
|
|
|
|
|
As Bernhard said, using string concatenation to build a SQL query will leave your code vulnerable to SQL Injection[^].
You wanted sample code:
using (var connection = new SqlConnection("YourConnectionStringGoesHere"))
using (var command = new SqlCommand("YourProcedureNameGoesHere", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@YourParameterName", "This parameter value's got an embedded apostrophe.");
connection.Open();
command.ExecuteNonQuery();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks you very much for advise ,
now I can insert apostrophe into database.
I have one more concern. If I am using above mentioned code,
How can I make class function to execute query.
Earlier I was passing a query(as string)to function, which will execute query. It gives flexibility to execute queries.
ie I could call function to execute any query.
Now, as parameters increases I need to create different query.
and I need to create separate code for deletion / updation / insertion.
Kindly provide a sample code to execute query as function as mentioned in above fashion
Thanks & Regards,
Praveen Machat
|
|
|
|
|
praveenmachat wrote: Kindly provide a sample code to execute query as function as mentioned in above fashion Just create a entity class with required fields like Name, Age, City. Assign values on UI layers & pass the class to this function.
public void execute(ClassEmployee objEmp)
using (var connection = new SqlConnection("YourConnectionStringGoesHere"))
using (var command = new SqlCommand("YourProcedureNameGoesHere", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@EmpName", objEmp.EmpName);
command.Parameters.AddWithValue("@EmpAge", objEmp.EmpAge);
command.Parameters.AddWithValue("@EmpCity", objEmp.EmpCity);
connection.Open();
command.ExecuteNonQuery();
}
} Check this article for reference
Creating ASP.NET Applications with N-Tier Architecture[^]
thatrajaCode converters | Education Needed
No thanks, I am all stocked up. - Luc Pattyn
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
|
|
|
|
|
Thank you for your kind response,
But my concern is ,how can i make function which will execute all queries.
otherwise for each query or Procedure in data base I need to create functions.
|
|
|
|
|
public static DataTable GetTable(SqlCommand cmd)
{
DataTable tbl = null;
SqlConnection conn = null;
try
{
conn =
cmd.Connection = conn;
tbl = new DataTable();
SqlDataReader dr = cmd.ExecuteReader();
tbl.Load(dr);
dr.Close();
dr.Dispose();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (conn != null)
{
conn.Close();
}
}
return tbl;
}
and in your main class you can call this function as
DataTable tbl = GetTable(cmd);
|
|
|
|
|
Can anyone give me a sample code to create multiple series dynamically and create a legend for all those series in asp.net chart control.
|
|
|
|
|
//design side:
<asp:chart id="yourchart" runat="server" Height="280px" Width="250px">
<titles>
<asp:Title ShadowOffset="3" Name="Title1" />
</titles>
<legends>
<asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="true" Name="Default" LegendStyle="Table" />
</legends>
<series>
<asp:Series Name="Default" /></series>
<chartareas>
<asp:ChartArea Name="ChartArea" BorderWidth="0" />
</chartareas>
</asp:chart>
yourchart.Series[0].XValueMember = "YourColumn";
yourchart.Series[0].YValueMembers = "YourColumn";
yourchart.Series["Default"].IsValueShownAsLabel = true;
yourchart.Series["Default"].ChartType = SeriesChartType.Pie;
yourchart.Series["Default"]["PieLabelStyle"] = "Disabled";
yourchart.ChartAreas["ChartArea"].Area3DStyle.Enable3D = false;
yourchart.Legends[0].Enabled = true;
LegendCellColumn LegendTextColumn = new LegendCellColumn();
LegendTextColumn.ColumnType = LegendCellColumnType.Text;
LegendTextColumn.Text = "#LEGENDTEXT";
yourchart.Legends["Default"].CellColumns.Add(LegendTextColumn);
|
|
|
|
|
I have some excel files on the server. When I am downloading them using asp.net, the downloaded excel file was corrupted. Below is my code. Could anyone tell me where I went wrong.
<pre lang="c#">
string filePath = Server.MapPath("docs\\sample.xls");
string filename = "sample";
HttpResponse res = HttpContext.Current.Response;
res.Clear();
res.AppendHeader("content-disposition", "attachment; filename=" + filename + ".xls");
res.ContentType = "application/octet-stream";
res.Write("<x:Name>" + filename + "</x:Name>");
res.WriteFile(filePath);
res.Flush();
res.End();
</pre>
|
|
|
|
|
Try changing your contentType to "application/vnd.ms-excel"
|
|
|
|
|
Kandepu Rajesh wrote: res.Write("<x:Name>" + filename + "</x:Name>"); That's the line that's causing the problem. You're adding a string to the start of a binary file, which is pretty-much guaranteed to corrupt it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I know there is a million ways to do this. But what I want to happen is to have a spreadsheet/excel that computes for something say grades. The user using the browser (client-side) inputs some integers, the spreadsheet computes. When the user commits. The next time he/she views it from the browser. The changes is there. Please help. Thanks codeproject community!
|
|
|
|
|
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
please help me
|
|
|
|
|
You have an error in your connection string, but not being able to see it or the code surrounding it makes it impossible to say what it is.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Things to check:
1. Make sure your database engine is configured to accept remote connections.
2. Check the SQL Server service account.
3. If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASP.NET application. Check you Connection Strings, probably issue is there.
4. You may need to create an exception on the firewall for the SQL Server instance and port you are using
5. Check SQLBrowser; check that it is running.
6. Check that you have connectivity to the SQL Server.
|
|
|
|
|
Hi
I have create three IFrame in same asp.page . But while logout from individual frame it is coming to login page with in frame
But i want to come out from total iframe page . Pl Help me for the code
|
|
|
|
|
are you want to log out from iframe? or you just want to close iframe?
|
|
|
|
|
I have a navigation bar which shows the type of recipe. eg: healthy recipe, desserts, etc...
I have a gridview on the same page. I want the data in the gridview to be populated as per the selection on navigation bar.
I am using VS2010 and sqldatasource to bind with database.
I google a lot but cant find any article based on populating gridview with context to navigation bar.
Plz help.
|
|
|
|
|
Try to Use Query String , in which you can pass any value through url, according to that value you an bind gridview using sql data source
http://www.dotnetperls.com/querystring[^]
follow this link you can learn how to use query string
|
|
|
|