|
This is my code for GridView and DataSource
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="LocationCode" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Edit" />
<asp:BoundField DataField="LocationCode" HeaderText="Location Code" ReadOnly="True"
SortExpression="LocationCode" />
<asp:BoundField DataField="LocationDesc" HeaderText="Desciption" SortExpression="LocationDesc" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=COMP2;Initial Catalog=Inventory;User ID=sa;Password=pes"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [LocationCode], [LocationDesc] FROM [Location_Master] ORDER BY [LocationCode]">
</asp:SqlDataSource>
I am editing data in database manually by using SqlCommand class ExecuteScalar method like this.......
protected void btnSave_Click(object sender, EventArgs e)
{
//This method will update a record into Location_Master table
try
{
string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
string save = "";
//String for updating a record into table
save = "update Location_Master set LocationDesc='" + txtBoxLocDesc.Text + "',CreatedBy='"+Session["userName"].ToString();
save = save + "',LastUpdateDate='" + System.DateTime.Now + "' where LocationCode='"+txtBoxLocCode.Text+"'";
SqlCommand saveCommand = new SqlCommand(save, connection);
int rowsAffected = saveCommand.ExecuteNonQuery(); //Store the no. of rows added or updated
connection.Close();
}
catch (System.Exception ex)
{
lblMessage.Text = ex.Message;
lblMessage.Visible = true;
}
}
After clicking that Save button, database is updating, but changes are not reflecting to GridView, i have to execute my application again to see changes in GridView.
|
|
|
|
|
SORRY for posting so large post, but i can't help it.
|
|
|
|
|
You have to use ExecuteScalar instead of ExecuteNonQuery .
int rowsAffected =(int) saveCommand.ExecuteScalar();
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
I don't think this will make much difference, we mostly use ExecuteNonQuery for updation purpose, i am getting my updations fine.
|
|
|
|
|
After updating the data base u need to bind data again with grid view again bind then data will come
gridview1.databind();
I hope this will u out
modified on Tuesday, August 25, 2009 7:29 AM
|
|
|
|
|
After update, call GridView1.DataBind() .
|
|
|
|
|
Hey thnx for all of those suggestions, i have worked it.
I call DataBind method both after making updation and also in Page_Load and it starts working.
I combined most of ur views.
Thanks to all again.
Nagendra.
|
|
|
|
|
Hello all, i have an application and it is giving me the error child node not allowed in web.comfig .
how should i proceed ?
|
|
|
|
|
|
Hi,
How to crete User control Dynamically?
Regards
Jayabharathi
|
|
|
|
|
rjayaabharathi@gmail.com wrote: How to crete User control Dynamically?
how far have you tried.... did you search something in google... a 2 seconds search in codeproject gives me this link...
Dynamic User Control, Ajaxify Your Controls[^]
|
|
|
|
|
hi,
i 'm not asked how to load user control dynamically?...
i have asked "HOw to create user control dynamically"
|
|
|
|
|
I have a datalist with 2 columns of products with a TextBox next to each product so my customer can enter a number in each checkbox (to determine the order sequence when this list of products is printed to the screen). I have a button for my customer to click when she is happy with the sequence chosen for each product and this calls a subroutine within which I need to be able to collect each productID and the number entered into the textbox next to it. This worked perfectly in my old system using Classic ASP and can't understand why it's so difficult to offer the same funtionality in ASP.Net! I have tried various approaches but none of them work in collecting the number entered into the TextBox and the ProdId at the same time. I tried storing the ProductId in the ID of the TextBox in the hope that I could then retrieve both the ProductId and the value of the TextBox for each product when the button is clicked but values of the TextBox ID are values such as 567 or 784 and are set dynamically (these are the productIds). The error I'm getting is as follows:
The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <asp:button runat="server" id="Button1">
and the line containing the error is:
<asp:textbox runat="server" id="<%# DataBinder.Eval(Container.DataItem, "Prod_ID")%>" text="<%# DataBinder.Eval(Container.DataItem, "Sequence1")%>">
Any advice would be greatly apreciated.
Thanks, Lorna
|
|
|
|
|
Hi All,
I am using Ajax ModalPopupExtender in my application. The code is given below
<asp:Panel ID="panelJobType" runat="server" CssClass="modalPopup">
<asp:Panel ID="panelJobTypeHead" runat="server" Style="cursor: move; background-color: #DDDDDD;
border: solid 1px Gray; color: Black">
<div>
<p>
Add the Job Type</p>
</div>
</asp:Panel>
<div>
<table>
<tr>
<td width="28" height="17">
</td>
<td align="left" valign="top" class="search" width="168" height="17">
Job Type:
</td>
<td align="left" valign="top" width="291" height="17">
<asp:TextBox ID="txt_Ctitle" runat="server" CssClass="border" size="25" MaxLength="50"></asp:TextBox>
<font class="msg">*</font>
</td>
</tr>
<tr>
<td colspan="3" height="5">
</td>
</tr>
<tr>
<td height="25" colspan="3">
</td>
</tr>
<tr>
<td colspan="3" bgcolor="074264" align="right" valign="bottom" class="heading5" height="25">
<asp:Button ID="btnSubmitJob" CssClass="rpt_btn" runat="server" Text="Save" />
<asp:Button ID="btnCancel" CssClass="rpt_btn" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server" TargetControlID="LinkButton1"
PopupControlID="panelJobType" BackgroundCssClass="modalBackground"
OkControlID="btnSubmitJob" CancelControlID="btnCancel"
DropShadow="true" PopupDragHandleControlID="panelJobTypeHead" />
Now what I want is to generate events from the buttons in the Panel.
For example I want to store the value of textbox into database by clicking on the button.
Is it possible??? and if yes than how.
Thanks in advance.
modified on Tuesday, August 25, 2009 5:47 AM
|
|
|
|
|
Hi All ,
I am loging into the web site after all validation i have to open another page in popup in which user select the hospital name then i have to redirect to index page.
Dim strScript As String
strScript = "<script language=javascript>" & vbCrLf & _
"window.opener.location.reload('index.aspx');window.close();" & _
vbCrLf & "</script>"
If Not ClientScript.IsClientScriptBlockRegistered("RefreshOpener") Then
ClientScript.RegisterStartupScript([GetType], "RefreshOpener", strScript)
Else
'lblError.Text = "Please Enter Valid Brokerage"
'lblError.Visible = True
End If
Thanks ,
This is working fine for IE but not for firefox
Amit
|
|
|
|
|
Amit Patel1985 wrote: This is working fine for IE but not for firefox
Install firebug[^] and debug the JS.
|
|
|
|
|
Hi,
I created a control and compile it. When I add it to an ASPX page it is
displayed fairly good at design time. But when I am trying to run it
an error has been raised.
Could not load file or assembly 'ServerTime' or one of its
dependencies. The located assembly's manifest definition does not match the
assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or
assembly 'ServerTime' or one of its dependencies. The located assembly's
manifest definition does not match the assembly reference. (Exception from
HRESULT: 0x80131040)
Source Error:
An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception
can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine
why the assembly 'ServerTime' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind
failure logging.
To turn this feature off, remove the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog].
Please help me with this.
|
|
|
|
|
Hi to all,
I am trying to add the menu items dynamically. But I am stucked in problem. I am unable to find the index of the menu items where menu text is "something".
public void populate_menu()
{
DataSet ds = GetMenuData();
foreach(DataRow drow in ds.Tables["CATEGORY"].Rows)
{
MenuItem masteritem = new MenuItem((string)drow["category_name"]);
name = masteritem.Text;
get_id();
par_id = Convert.ToInt32 (ViewState["p_id"]);
if (par_id == 0)
{
Menu1.Items.Add(masteritem);
}
else
{
get_category_name();
ca_name = ViewState["cname"].ToString();
Menu1.Items[0].ChildItems.Add(masteritem);
}
}
}
please assist me..
cheers,
sneha
|
|
|
|
|
I guess you need to maintain a value path and work with Menu.FindItem()[^] method.
Other way is to recursively search the menu items and sub items until you get the required item.
|
|
|
|
|
Hello every one,I have some images in mysql data base .I am trying to get it in web page.I am writing following code but i am getting error some array outof Rang exception.Please give me the solution.The code is as follow
OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
OdbcDataAdapter da = new OdbcDataAdapter("select Image from test4", con);
DataSet ds = new DataSet();
da.Fill(ds, "test4");
DataRow row=ds.Tables ["test4"].Rows [0];
byte[] image = (byte[])row["Image"];
Response.BinaryWrite(image);
|
|
|
|
|
hi,
You can try like this:
cmd = new OleDbCommand("select * from gallery where event_id='"+ id +"'", conn);
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
cmd1 = new OleDbCommand("select event_name from events where event_id=" + id, conn);
dr1 = cmd1.ExecuteReader();
dr1.Read();
lblevent.Text = "<h3>" + dr1[0].ToString() + "</h3>";
lblevent.Text = lblevent.Text + "<p>";
dr1.Close();
while (dr.Read())
{
lblevent.Text = lblevent.Text + "<a href='images/events/" + dr[3].ToString() + "' rel=\"lightbox[events Photos]\"><img src=\"images/events/thumb/" + dr[2].ToString() + " \" alt='' width=\"100\" height=\"96\" border=\"1\" /></a>";
}
lblevent.Text = lblevent.Text + "</p>";
cheers,
sneha
|
|
|
|
|
Well, I guess that you don't have a single row in your table. I would try to debug the code, setting a breakpoint where you access the row.
Regards
Sebastian
|
|
|
|
|
I am writting this syntex for insert. its showing syntex error in insert.plz tell me the correct one.
INSERT INTO Registration (DATE OF BIRTH,CONTACT NUMBER) VALUES('" + DateT.Text + "','" + ContactT.Text + "')
|
|
|
|
|
I think you haven't read any book on SQL, you have no idea about T-SQL.
In this statement you should use [] in column name because there are spaces in column name (which is not a good practice).
Second you should pass parameters...
Be an Eagle, Sky is Yours.
|
|
|
|
|
Hi,
You should use parameter mapping to avoid sql injection.
cheers,
sneha
|
|
|
|