Click here to Skip to main content
15,902,447 members
Home / Discussions / C#
   

C#

 
GeneralRe: HTTP Post Request Pin
eggie529-Jan-05 13:08
eggie529-Jan-05 13:08 
GeneralRe: HTTP Post Request Pin
notacake30-Jan-05 1:06
notacake30-Jan-05 1:06 
GeneralRe: HTTP Post Request Pin
leppie30-Jan-05 3:04
leppie30-Jan-05 3:04 
GeneralRe: HTTP Post Request Pin
notacake30-Jan-05 3:07
notacake30-Jan-05 3:07 
QuestionGenerating Buttons dynamically at runtime? Pin
E6AD29-Jan-05 12:36
E6AD29-Jan-05 12:36 
AnswerRe: Generating Buttons dynamically at runtime? Pin
therealmccoy29-Jan-05 17:29
therealmccoy29-Jan-05 17:29 
GeneralRe: Generating Buttons dynamically at runtime? Pin
E6AD5-Feb-05 16:56
E6AD5-Feb-05 16:56 
GeneralEditing problem in Datagrid Pin
29-Jan-05 10:29
suss29-Jan-05 10:29 
Hi,
I've a datagrid connected to one table from postgres database. I'm using ODBC. Also, table has only 3 columns, out of which I'm using only 2 columns, and I'mve added these columns to datagrid manually.
Now, when I try to edit ot even try to add new row after postback it doesnt seem to work! The form doesnt do anything.

There is another form where I'm creating and populating (basically handling everything at runtime) and there the same piece of code is working just fine!

Here is the code of the form that is not working...

<--CODE-ASPX-START-->
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 38px; POSITION: absolute; TOP: 17px" runat="server" autogeneratecolumns="False" bordercolor="Silver" borderwidth="1px">
<columns>
<asp:buttoncolumn text="Add" buttontype="PushButton" headertext="New" commandname="AddNewRow">

<asp:editcommandcolumn buttontype="PushButton" updatetext="Update" headertext="Change" canceltext="Cancel" edittext="Edit">

<asp:boundcolumn datafield="url_name" headertext="Url Name">

<asp:boundcolumn datafield="url_comments" headertext="Comments">



<asp:linkbutton id="LinkButton2" style="Z-INDEX: 106; LEFT: 208px; POSITION: absolute; TOP: 312px" runat="server" forecolor="Black" font-names="Verdana" font-size="10pt">Make Changes
<asp:linkbutton id="LinkButton1" runat="server" style="Z-INDEX: 107; LEFT: 100px; POSITION: absolute; TOP: 311px" forecolor="Black" font-names="Verdana" font-size="10pt">Add New





<--CODE-ASPX-END-->

<--CODE-ASPX.CS-START-->
private void Page_Load(object sender, System.EventArgs e)
{
string connectionStr = "DRIVER={PostgreSQL}; SERVER=localhost;UID=xxx;PASSWORD=xxx;Trusted_connection=false;DATABASE=marketing;";
string str = "select pk_url,url_name,url_comments FROM urls;";
connection = new OdbcConnection(connectionStr);
connection.Open();
selectCommand = new OdbcCommand(str,connection);
adapter = new OdbcDataAdapter(selectCommand);
ds = new DataSet();
adapter.Fill(ds,"urls");
DataGrid1.DataSource = ds;
DataGrid1.DataMember = "urls";
DataGrid1.DataBind();
connection.Close();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.DataGrid1.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemCreated);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Response.Write("Am I Editing!!!");
Response.Write("
e.item.itemindex: "+e.Item.ItemIndex);
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}

private void AddNewRow()
{
DataRow dr = ds.Tables[0].NewRow();
int loc = ds.Tables["urls"].Rows.Count;
ds.Tables["urls"].Rows.InsertAt(dr,loc);
ds.AcceptChanges();
DataGrid1.DataBind();
DataGrid1.EditItemIndex = loc;
}

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.DataGrid1.SelectedItem.Attributes["onmouseover"] = "this.style.cursor='hand'";
this.DataGrid1.SelectedItem.Attributes.Remove("onmouseout");
if(this.DataGrid1.EditItemIndex >= 0)
{
this.DataGrid1.EditItemIndex = -1;
this.DataGrid1.DataBind();
}
}

private void LinkButton2_Click(object sender, System.EventArgs e)
{
this.DataGrid1.EditItemIndex = this.DataGrid1.SelectedIndex;
this.DataGrid1.DataBind();
}

private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem) | (e.Item.ItemType == ListItemType.SelectedItem))
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor = 'thistle';this.style.cursor='hand'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor = 'gray'");
e.Item.Attributes.Add("onclick",GetPostBackEventReference(e.Item));
e.Item.Attributes.Add("onclick","javascript:__doPostBack(\'" + "DataGrid1:" + "_ctl" + (e.Item.ItemIndex+2) + ":_ctl0\',\' \')");
}
}
}
}


<--CODE-ASPX.CD-END-->

One more thing, as you can see I've tried adding buttonColumns in datagrid as well as withought those. But nothing seem to work!

Any, as in any suggestion is apprecitated

thanks



shatru2k
GeneralRe: Editing problem in Datagrid Pin
xrado24-Jun-05 0:31
xrado24-Jun-05 0:31 
Questionhow to send same request to different terminals at the same time and wait for the response... Pin
just_starting29-Jan-05 9:14
just_starting29-Jan-05 9:14 
AnswerRe: how to send same request to different terminals at the same time and wait for the response... Pin
mav.northwind29-Jan-05 11:19
mav.northwind29-Jan-05 11:19 
GeneralC# windows Timer question... Pin
new_phoenix29-Jan-05 6:13
new_phoenix29-Jan-05 6:13 
GeneralRe: C# windows Timer question... Pin
eggie529-Jan-05 11:28
eggie529-Jan-05 11:28 
GeneralRe: C# windows Timer question... Pin
new_phoenix29-Jan-05 11:59
new_phoenix29-Jan-05 11:59 
GeneralRe: C# windows Timer question... Pin
eggie529-Jan-05 13:04
eggie529-Jan-05 13:04 
GeneralRe: C# windows Timer question... Pin
Robert Rohde29-Jan-05 21:24
Robert Rohde29-Jan-05 21:24 
GeneralRe: C# windows Timer question... Pin
new_phoenix1-Feb-05 5:34
new_phoenix1-Feb-05 5:34 
GeneralClass problem Pin
thepersonof29-Jan-05 5:44
thepersonof29-Jan-05 5:44 
GeneralRe: Class problem Pin
Robert Rohde29-Jan-05 7:13
Robert Rohde29-Jan-05 7:13 
GeneralI need to control device volum Pin
FedorMatv29-Jan-05 3:02
FedorMatv29-Jan-05 3:02 
GeneralRemoting Configuration Files and the new Operator Pin
STW28-Jan-05 21:31
STW28-Jan-05 21:31 
GeneralIs it possible to create a treeview control that have owner draw scrollbar Pin
god4k28-Jan-05 20:55
god4k28-Jan-05 20:55 
GeneralLINK ERROR 1181: beginner quest. Pin
...---...28-Jan-05 16:09
...---...28-Jan-05 16:09 
GeneralHashTable access question Pin
pkellner28-Jan-05 14:00
pkellner28-Jan-05 14:00 
GeneralRe: HashTable access question Pin
Robert Rohde28-Jan-05 19:28
Robert Rohde28-Jan-05 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.